Home > Blockchain >  How to remove mirror duplicate pair rows in pandas?
How to remove mirror duplicate pair rows in pandas?

Time:03-20

This is my dataframe consisting of columns a,b,c,d. enter image description here

Here

1 2 3 4

has mirror duplicate pair row of

3 4 1 2

Removing the duplicate pair should give me enter image description here

CodePudding user response:

df.loc[pd.DataFrame(np.sort(df[['a','b','c','d']],1),index=df.index).drop_duplicates(keep='first').index]

U can use np.sort to sort columns in ascending order and then use .drop duplicates to get rid of the duplicate rows.

  • Related