Home > Net >  Pandas: Read a sample of a DataFrame [duplicate]
Pandas: Read a sample of a DataFrame [duplicate]

Time:09-16

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.

CodePudding user response:

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)

CodePudding user response:

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