I am trying to drop multiple rows from my data. I can drop rows using:
dt=dt.drop([40,41,42,43,44,45])
But I was wondering if there is a simpler way. I tried:
dt=dt.drop([40:45])
But sadly it did not work.
I am trying to drop multiple rows from my data. I can drop rows using:
dt=dt.drop([40,41,42,43,44,45])
But I was wondering if there is a simpler way. I tried:
dt=dt.drop([40:45])
But sadly it did not work.
I will recommend np.r_
df.drop(np.r_[40:50+1])
In case you want to drop two range at the same time
np.r_[40:50+1,1:4+1]
Out[719]: array([40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4])
Assuming you want to drop a range of positions:
df.drop(df.index[40: 46])
This doesn't assume the indices are integers.
You can use:
dt = dt.drop(range(40,46))
or
dt.drop(range(40,46), inplace=True)
You could generate the list based on a range:
dt=dt.drop([x for x in range(40, 46)])
Or just:
dt=dt.drop(range(40, 46))