删除数据帧中的重复行 [英] Remove duplicate rows in a dataframe
本文介绍了删除数据帧中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据框中删除重复的行,具体取决于列。
I would like to remove duplicate rows from my dataframe depending on a specific column.
这里简化了我的数据框的一个例子:
Here an example of my dataframe simplified:
Code Weight
100 20
100 25
100 20
100 18
200 13
200 13
200 13
200 20
300 69
300 50
300 50
300 13
输出应为:
Code Weight
100 20
100 25
100 18
200 13
200 20
300 69
300 50
300 13
换句话说,我必须从每个代码子集中删除重复的行。
我想我可以使用唯一的,但我不知道在这种特殊情况下如何。
In other words I have to remove duplicate rows from each Code subset. I think I can use unique but I don't know how in this particular case.
在我的真实数据框中,我有7个不同值的列在代码和重量之间。
In my real dataframe I have got 7 more columns with different values between "Code" and "Weight".
任何建议?
推荐答案
p>我们可以使用重复的
df1[!duplicated(df1),]
# Code Weight
#1 100 20
#2 100 25
#4 100 18
#5 200 13
#8 200 20
#9 300 69
#10 300 50
#12 300 13
或独特
unique(df1)
这篇关于删除数据帧中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文