Skip to content Skip to sidebar Skip to footer

Python: Separate Out Rows Which Have Duplicates In Panda Dataframe

Suppose a data frame df has three columns 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(

Solution 1:

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)]

Solution 2:

df1=df[df.duplicated(keep=False)]

this option delete all duplicates, defalult pandas keep first appear.

Post a Comment for "Python: Separate Out Rows Which Have Duplicates In Panda Dataframe"