Head & Tail
To view a small sample of a Series or the DataFrame object, use the head() and the tail() methods.
head() returns the first n rows(observe the index values). The default number of elements to display is five, but you may pass a custom number.
#head()-Returns the first n rows.,
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(4))
print ("The original series is:")
print (s)
print ("The first two rows of the data series:")
print s.head(2)
The original series is:
0 0.720876
1 -0.765898
2 0.479221
3 -0.139547
The first two rows of the data series:
0 0.720876
1 -0.765898
#tail()- Returns the last n rows.
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(4))
print ("The original series is:")
print s
print ("The last two rows of the data series:")
print s.tail(2)
The original series is:
0 -0.655091
1 -0.881407
2 -0.608592
3 -2.341413
The last two rows of the data series:
2 -0.608592
3 -2.341413
dtype: float64