需要一些关于从pandas数据帧中获取唯一值的帮助。
我有以下内容:
我有以下内容:
>>> df1
source target metric
0 acc1.yyy acx1.xxx 10000
1 acx1.xxx acc1.yyy 10000
目标是基于源+目标或目标+源来删除唯一值。但使用drop_duplicates不能实现此目标。
>>> df2 = df1.drop_duplicates(subset=['source','target'])
>>> df2
source target metric
0 acc1.yyy acx1.xxx 10000
1 acx1.xxx acc1.yyy 10000
[更新]
也许“重复”不是这里的正确词汇,让我进一步解释。
id source target
0 bng1.xxx.00 bdr2.xxx.00
1 bng1.xxx.00 bdr1.xxx.00
2 bdr3.yyy.00 bdr3.xxx.00
3 bdr3.xxx.00 bdr3.yyy.00
4 bdr2.xxx.00 bng1.xxx.00
5 bdr1.xxx.00 bng1.xxx.00
根据上述要求,我希望删除那些源等于目标且目标等于源的条目。
0 and 4 = same pair
1 and 5 = same pair
2 and 3 = same pair
end goal will be to keep 0 1 2 or 4 5 3 .