pandas Indexing and selecting data Get the first/last n rows of a dataframe


To view the first or last few records of a dataframe, you can use the methods head and tail

To return the first n rows use DataFrame.head([n])


To return the last n rows use DataFrame.tail([n])


Without the argument n, these functions return 5 rows.

Note that the slice notation for head/tail would be:

df[:10]  # same as df.head(10)
df[-10:] # same as df.tail(10)