2

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.

Ali Youssef
  • 485
  • 7
  • 20
  • Read the Pandas documentation. – AMC Feb 22 '20 at 18:58
  • Does this answer your question? [Selecting a row of pandas series/dataframe by integer index](https://stackoverflow.com/questions/16096627/selecting-a-row-of-pandas-series-dataframe-by-integer-index) – AMC Feb 22 '20 at 18:59

1 Answers1

3

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]
Valdi_Bo
  • 27,886
  • 3
  • 21
  • 36