0

I have a dataframe such as :

Element1 Group1 Element2 Group2
A        G1     B        G1
C        G1     D        G2
E        G6     F        G9
G        G6     H        G9
I        G12    J        G9
K        G12    L        G9
M        G11    N        G9

And I would like within each Group1 and Group2 columns to keep only one representant of both duplicated groups within Group1 and Group2

For instance G6 is present twice as well as G9, so I keep only one the row with E and F (the first row to appear ). Then for G12 and G9.

I should then get:

Element1 Group1 Element2 Group2
A        G1     B        G1
C        G1     D        G2
E        G6     F        G9
I        G12    J        G9
M        G11    N        G9

Note: it is not a duplicate of Remove duplicates from dataframe, based on two columns A,B, keeping row with max value in another column C since I do not remove for instance :

Element1 Group1 Element2 Group2
A        G1     B        G1
C        G1     D        G2
chippycentra
  • 2,838
  • 1
  • 5
  • 14

0 Answers0