假设数据框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只有一行,即
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)]
,它会给我错误
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'
答案 0 :(得分:2)
您为 keep 指定的值是多少。我认为,在你的情况下,传递假,因为保持值可能会解决问题。 Pandas Duplicated Doc's 。希望它有所帮助。
df1 = df[df.duplicated(keep=False)]
答案 1 :(得分:0)
$('input[type=file]').change(test);
此选项删除所有重复项,defalult pandas首先出现。