我有一个很大的数据框。这里是一个小例子。熊猫:得到删除行索引
C1 C2 C3 C4
0 foo one 1 4
1 foo one 1 5
2 foo two 2 3
3 bar one 3 6
4 bar two 2 7
我执行删除多行的过滤器列表。下面是最终DF
C1 C2 C3 C4
0 foo one 1 4
2 foo two 2 3
3 bar one 3 6
我要的是删除线的指数,这样我就可以被拒绝输出的所有值这一点。
我有一个很大的数据框。这里是一个小例子。熊猫:得到删除行索引
C1 C2 C3 C4
0 foo one 1 4
1 foo one 1 5
2 foo two 2 3
3 bar one 3 6
4 bar two 2 7
我执行删除多行的过滤器列表。下面是最终DF
C1 C2 C3 C4
0 foo one 1 4
2 foo two 2 3
3 bar one 3 6
我要的是删除线的指数,这样我就可以被拒绝输出的所有值这一点。
你可以使用的两个指标的对象difference
方法:
>>> df_orig.index.difference(df_final.index)
Int64Index([1, 4], dtype='int64')
如果您使用一个版本的熊猫没有这个,你可以使用np.setdiff1d
来代替:
>>> np.setdiff1d(df_orig.index, df_final.index)
array([1, 4], dtype=int64)
非常感谢!我不知道差别命令 – Sara 2015-04-04 13:37:26
你能首先找到需要删除的行的索引,然后用'drop'删除它们吗? – 2015-04-03 17:36:21
我认为您正在寻找'index.difference' – cel 2015-04-03 17:37:34