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?
You can create a series by calling pandas. Series() . An list, numpy array, dict can be turned into a pandas series. You should use the simplest data structure that meets your needs.
A Pandas Series is like a column in a table. It is a one-dimensional array holding data of any type.
We can easily create an empty series in Pandas which means it will not have any value. The syntax that is used for creating an Empty Series: <series object> = pandas. Series()
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With