大熊猫在两列之间删除重复

时间:2017-02-02 14:59:52

标签: python pandas

我正在寻找在Pandas数据框中删除两列之间重复的有效方法。所以,我的数据是,

   A  B 
0  1  0  
1  1  1  
2  nan  2  
3  8  3
4  7  7

我想知道,

   A  B 
0  1  0  
1 nan  2  
2  8  3

我怎样才能获得这样的输出?谢谢!

1 个答案:

答案 0 :(得分:5)

试试这个:

df = df[df.A != df.B]

按要求使用循环:

dups_index = []
for i, row in df.iterrows():
    if row['A'] == row['B']:
        dups_index.append(i)
df = df[~df.index.isin(dups_index)]
相关问题