How to create a series of numbers using Pandas in Python

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

+12
source share
4 answers

As you can see from the docs for pandas.Series , all that is required for your parameter datais an array-like, dict, or scalar value. Therefore, to create a series for a range, you can do the same as creating a list for a range.

one_to_hundred = pd.Series(range(1,101))
+16
source
one_to_hundred=pd.Series(np.arange(1,101,1))

, , numpy arange, , 1 100, 1.

+3

Num = np.arange(1101)

S = pd.Series(NUM)

to see a solution just change what you want. and for details about np.arange see below link https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.arange.html

+1
source

There is 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.

0
source

All Articles