Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame head() Method

❮ DataFrame Reference


Return the first 5 rows of the DataFrame.

In this example we use a .csv file called data.csv

import pandas as pd

df = pd.read_csv('data.csv')

Try it Yourself »

Definition and Usage

The head() method returns a specified number of rows, string from the top.

The head() method returns the first 5 rows if a number is not specified.


Note: The column names will also be returned, in addition to the specified rows.




Parameter Description
n Optional. The number of rows to return. Default value is 5.

Return Value

A DataFrame with headers and the specified number of rows.

❮ DataFrame Reference