Let us assume we have the following Series:
>>> import pandas as pd
>>> s = pd.Series([1, 4, 6, 3, 8, 7, 4, 5])
>>> s
0 1
1 4
2 6
3 3
4 8
5 7
6 4
7 5
dtype: int64
Followings are a few simple things which come handy when you are working with Series:
To get the length of s:
>>> len(s)
8
To access an element in s:
>>> s[4]
8
To access an element in s using the index:
>>> s.loc[2]
6
To access a sub-Series inside s:
>>> s[1:3]
1 4
2 6
dtype: int64
To get a sub-Series of s with values larger than 5:
>>> s[s > 5]
2 6
4 8
5 7
dtype: int64
To get the minimum, maximum, mean, and standard deviation:
>>> s.min()
1
>>> s.max()
8
>>> s.mean()
4.75
>>> s.std()
2.2519832529192065
To convert the Series type to float:
>>> s.astype(float)
0 1.0
1 4.0
2 6.0
3 3.0
4 8.0
5 7.0
6 4.0
7 5.0
dtype: float64
To get the values in s as a numpy array:
>>> s.values
array([1, 4, 6, 3, 8, 7, 4, 5])
To make a copy of s:
>>> d = s.copy()
>>> d
0 1
1 4
2 6
3 3
4 8
5 7
6 4
7 5
dtype: int64