How do I read the first 10 rows of a Pandas DataFrame?

Viewed 676

I am looking for a way to read a sample of a DataFrame in pandas like:

df = pd.read_csv('path_to_my_csv/csv.csv', header=True, sample=10)

#or 
df = pd.read_parquet('path_to_my_parquet/csv.parquet', engine="pyarrow", sample=10)

What I want is to load on the X (10 is this case) first rows of my Data, for test purpose.

2 Answers

You can load only the first 10 non-header rows using nrows

df = pd.read_csv('path_to_my_csv/csv.csv', header=True, nrows=10)
df = pd.read_csv('path_to_my_csv/csv.csv', header=True).head(10)

Your df will have the first 10 rows of your csv file

Related