我正在寻找有效的方法来删除 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
我怎样才能得到这样的输出?谢谢!
最佳答案
试试这个:
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)]
关于python - Pandas 在两列之间删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42005500/