Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame head() Method

❮ DataFrame Reference


Example

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')

print(df.head())
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.


Syntax

dataframe.head(n)

Parameters

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