Pandas Head β Preview Data β DataFrame.head()
Return top n rows of a Pandas DataFrame
Pandas Head might be our single most used function in the library. It is essential for quickly testing to ensure your data is correct, especially with a notebook type environment.
Pandas Head will return the top n-number of rows of your DataFrame. It is essential for checking to make sure your data is what you think it is. Itβs close cousin, Pandas Tail will return the bottom n-number of rows.
Pseudo code: Return the top n-rows of a Pandas DataFrame.
Pandas Head
Head Parameters
.head()
only has one parameter and itβs super easy: How many rows do you want to preview?
- n (Default=5): The number of rows youβd like to preview. By default Pandas will show you 5 rows. I most often use the default, but occasionally Iβll only do n=1 or n=10.
Pandas Tail is the exact same thing as Pandas Head but youβll be returned with the last rows of a DataFrame instead of first rows.
If you wanted a random sample of N rows, then check out Pandas Sample.
Letβs look at an example