October 2019
Beginner to intermediate
674 pages
16h 43m
English
In this case, the index must be the same length as the data. The following example creates a Series structure of seven random numbers between 0 and 1; the index is not specified:
In [4]: ser = pd.Series(np.random.randn(7))In [5]: serOut[5]:0 3.0639211 0.0974502 -1.6603673 -1.2213084 -0.9488735 0.4544626 0.586824dtype: float64
An index can also be string objects. The following example creates a Series structure of the first five months of the year with a specified index of month names:
In [6]: import calendar as calIn [7]: monthNames=[cal.month_name[i] for i in np.arange(1,6)]In [8]: months = pd.Series(np.arange(1,6), index = monthNames)In [10]: monthsOut[10]:January 1February 2March 3April 4May 5dtype: int32In [11]: months.index ...
Read now
Unlock full access