我想从数据框的底部删除m行。它是用整数索引(带空洞)的。如何实现?
pandas == 0.10.1 python == 2.7.3
使用切片选择您想要的部分:
df[:-m]
如果你想删除一些中间行,可以使用drop
:df.drop(df.index[3:5])
以下是一个示例,其中您想要删除的范围是从x到y的索引,我将其设置为0和10
选择仅在0到10之间的位置,以查看行以确认后再删除
x=0 # could change x and y to a start and end date
y=10
df.loc[x:y]
选择索引
df.loc[x:y].index
移除数据帧中的选定内容
df.drop(df.loc[x:y].index, inplace=True)
df.head(len(df) - m)
df.head(-m)
。 - rachwailoc
方法,该方法使用数据集中的行/列位置而不是实际索引。因此,要删除最后的m
行,您可以使用以下代码:df.iloc[:-m]
data_0 = data_0.drop(data_0.index['2016-01-28 12:00:00':'2016-01-28 12:02:30'])
来删除这个时间段,但是出现了错误:AttributeError: '_IXIndexer' object has no attribute 'drop'
。 - nandhos