我使用pandas的nsmallest
来查找特定列中具有最小值的n行,如果我理解正确,它将返回一个数据帧对象;如何从数据帧中删除这些行?pandas的drop
只得到行索引,而不是数据帧
删除series
(或特定列(的3个最小值:
>>> sr
0 22 # <- drop
1 45 # <- drop
2 61
3 65
4 74
5 78
6 58
7 73
8 13 # <- drop
9 91
dtype: int64
>>> sr.nsmallest(3)
8 13
0 22
1 45
dtype: int64
>>> sr.drop(sr.nsmallest(3).index)
2 61
3 65
4 74
5 78
6 58
7 73
9 91
dtype: int64