Reputation: 655
Suppose we have a dataframe df
df=pd.DataFrame()
df['c1']=[1,2,3,3,4]
df['c2']=["a1","a2","a2","a2","a1"]
df['c3']=[1,2,3,3,5]
If I use either df.drop_duplicates(keep=False)
or df.duplicated(keep=False)
, I get the following error:
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'
Upvotes: 0
Views: 5018
Reputation: 31672
You should update your pandas version because it's added from 0.17.0
version, from what's new in v. 0.17.0:
drop_duplicates
andduplicated
now accept akeep
keyword to target first, last, and all duplicates.
Both works in pandas 0.18.1
:
In [116]: df
Out[116]:
c1 c2 c3
0 1 a1 1
1 2 a2 2
2 3 a2 3
3 3 a2 3
4 4 a1 5
In [117]: df.drop_duplicates()
Out[117]:
c1 c2 c3
0 1 a1 1
1 2 a2 2
2 3 a2 3
4 4 a1 5
In [118]: df.drop_duplicates(keep=False)
Out[118]:
c1 c2 c3
0 1 a1 1
1 2 a2 2
4 4 a1 5
Upvotes: 2