How to create a series of numbers using Pandas in Python

MrCurious picture MrCurious · Apr 16, 2016 · Viewed 44.1k times · Source

I am new to python and have recently learnt to create a series in python using Pandas. I can define a series eg: x = pd.Series([1, 2, 3, 4, 5]) but how to define the series for a range, say 1 to 100 rather than typing all elements from 1 to 100?

Answer

miradulo picture miradulo · Apr 16, 2016

As seen in the docs for pandas.Series, all that is required for your data parameter is an array-like, dict, or scalar value. Hence to create a series for a range, you can do exactly the same as you would to create a list for a range.

one_to_hundred = pd.Series(range(1,101))