Skip to content
LearnPY
pandasfunction reference

DataFrame.head

Return the first rows of a DataFrame or Series.

Signature

DataFrame.head(n=5)

What it does

head is a quick inspection tool. It returns a new object containing the first n rows and leaves the original unchanged. Use tail for the last rows.

Parameters

nint, optionaloptional
Number of rows to return. Defaults to 5.

Returns

DataFrame or Series

Example

pythonDataFrame.head example
import pandas as pd

df = pd.DataFrame({"score": [10, 12, 8, 15, 9, 11]})
print(df.head(2))

Output

   score
0     10
1     12

Watch out for

  • head prints a preview but does not modify the DataFrame.
  • A negative n returns every row except the last |n| rows, which is rarely what you want.