PANDAS drop a range of rows from df


Question

I want to drop m number of rows from the bottom of a data frame. It is integer indexed (with holes). How can this be done?

pandas == 0.10.1 python == 2.7.3

1
9
3/29/2013 12:31:28 PM

Accepted Answer

Use slice to select the part you want:

df[:-m]

If you want to remove some middle rows, you can use drop:

df.drop(df.index[3:5])
17
3/29/2013 12:53:14 PM

This should work

df.head(len(df) - m)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon