AliY
AliY

Reputation: 557

How to select certain number of rows in data frame?

So I have a dataframe that is (2624229, 574) and I would like to select only the first 864000 rows, but I can't figure out how to do it.

Thank you.

Upvotes: 2

Views: 12244

Answers (1)

Valdi_Bo
Valdi_Bo

Reputation: 30991

One of possible solutions is to use iloc:

n = 864000
df.iloc[:n]

The above code retrieves initial n rows (for now df holds all rows). But if you want to drop all rows beyond this limit, run:

df = df.iloc[:n]

Upvotes: 5

Related Questions