我有数据帧:
df = pd.read_csv(...)
a b c d e f
1 two adc aaaa Nan mmm
2 one Nan aaa Nan nnn
1 one ab Nan Nan ww
1 two abcd aaa ff uiww
1 two a aaa d iii
我想根据“a”和“b”删除副本。你知道吗
df = df.drop_duplicates(['a', 'b'])
我想得到这个结果:
a b c d e f
1 two abcd aaaa ff uiww
2 one Nan aaa Nan nnn
1 one ab Nan Nan ww
我尝试使用transform
和apply
,但不可能简化为一个方案。实现这一目标最有效的方法是什么?你知道吗
根据您的条件创建函数,然后使用
agg
和groupby
除非需要使用groupby(对于大数据帧来说,groupby的速度很慢),否则可以执行以下操作:
希望这有帮助
相关问题 更多 >
编程相关推荐