Peeking at data with heads, tails, and take
pandas provides the .head()
and .tail()
methods to examine just the first few, or last, records in a Series
. By default, these return the first or last five rows, respectively, but you can use the n
parameter or just pass an integer to specify the number of rows:
In [23]: # first five s.head() Out[23]: 0 0 1 1 2 1 3 2 4 3 dtype: float64 In [24]: # first three s.head(n = 3) # s.head(3) is equivalent Out[24]: 0 0 1 1 2 1 dtype: float64 In [25]: # last five s.tail() Out[25]: 5 4 6 5 7 6 8 7 9 NaN dtype: float64 In [26]: # last 3 s.tail(n = 3) # equivalent to s.tail(3) Out[26]: 7 6 8 7 9 NaN dtype: float64
The .take()
method will return the rows in a series that correspond to ...
Get Learning pandas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.