python:分离出在 pandas 数据帧中有重复的行 [英] python: separate out rows which have duplicates in panda dataframe
本文介绍了python:分离出在 pandas 数据帧中有重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设数据框 df
有三列 c1,c2,c3
。
df=pd.DataFrame()
df['c1']=[1,2,3,3,4]
df['c2']=["a1","a2","a2","a2","a1"]
df['c3']=[1,2,3,3,5]
print df
df1=df[df.duplicated()]
print df1
df1只有一行,这是
df1 has only one row, which is
c1 c2 c3
3 3 a2 3
但我想要有
c1 c2 c3
2 3 a2 3
3 3 a2 3
如何得到它?还有一件事,如果我尝试使用参数'keep'作为 df1 = df [df.duplicated(keep = False)]
,它给我错误
How to get it? One more thing, if I try to use argument 'keep' as df1 = df[df.duplicated(keep=False)]
, it gives me error
Traceback (most recent call last):
File "<ipython-input-572-188a22102b3e>", line 1, in <module>
df1 = df[df.duplicated(keep=False)]
File "C:\Users\Kanika\Anaconda\lib\site-packages\pandas\util\decorators.py", line 88, in wrapper
return func(*args, **kwargs)
TypeError: duplicated() got an unexpected keyword argument 'keep'
推荐答案
您为保留指定的值。我认为,在你的情况下传递False作为保留值可能会解决问题。 熊猫重复文件。希望它有帮助。
What is the value that you specified for keep . I think, In your case Passing False as the keep value might solve the issue. Pandas Duplicated Doc's . Hope it helps.
df1 = df[df.duplicated(keep=False)]
这篇关于python:分离出在 pandas 数据帧中有重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文