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.

The Singularity
  • 2,428
  • 3
  • 19
  • 48
PicxyB
  • 596
  • 2
  • 8
  • 27

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)
The Singularity
  • 2,428
  • 3
  • 19
  • 48
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
  • 63
  • 5