1

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.

Luke
  • 1,741
  • 10
  • 29
PicxyB
  • 331
  • 4
  • 18

2 Answers2

3

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)
Luke
  • 1,741
  • 10
  • 29
0
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

snag9677
  • 53
  • 5