How to create a series of numbers using Pandas in Python

try pd.Series([0 for i in range(20)]). It will create a pd series with 20 rows


one_to_hundred=pd.Series(np.arange(1,101,1))

This is the correct answer where you create a series using the numpy arange function which creates a range starting with 1 till 100 by incrementing 1.


There's also this:

one_to_hundred = pd.RangeIndex(1, 101).to_series()

I'm still looking for a pandas function that creates a series containing a range (sequence) of numbers directly, but I don't think it exists.


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))