Python Pandas Library head function

27 June 2023 68 Reading time: 18 second

The head function in the Pandas library returns the first n rows of a DataFrame. By default, the value of n is 5, but it can be optionally specified as a different value.


import pandas as pd

df = pd.read_csv('data.csv')
# Get the first 3 rows of the DataFrame
first_three_rows = df.head(3)


Similar articles