Pandas Series provides two very useful methods for extracting the data from the top and bottom of the Series Object. These methods are head() and tail().
head() Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import pandas as pd s = pd.Series({'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8}) print(s) Output: A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 dtype: int64 |
head() Function without argument
1 2 3 4 5 6 7 8 9 | s.head() Output: A 1 B 2 C 3 D 4 E 5 dtype: int64 |
head() Function with Positive Argument
1 2 3 4 5 6 7 8 9 10 11 | s.head(7) Output: A 1 B 2 C 3 D 4 E 5 F 6 G 7 dtype: int64 |
head() Function with Negative Argument
1 2 3 4 5 | s.head(-7) Output: A 1 dtype: int64 |
tail() Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import pandas as pd s = pd.Series({'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8}) print(s) Output: A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 dtype: int64 |
tail() function without argument
1 2 3 4 5 6 7 8 9 10 | s.tail() ''' Output: D 4 E 5 F 6 G 7 H 8 dtype: int64 ''' |
tail() function Positive argument
1 2 3 4 5 6 7 8 9 10 11 12 | s.tail(7) ''' Output: B 2 C 3 D 4 E 5 F 6 G 7 H 8 dtype: int64 ''' |
tail() function Negative argument
1 2 3 4 5 6 | s.tail(-7) ''' Output: H 8 dtype: int64 ''' |