Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Match two columns in dataframe

I have two columns in dataframe df

  ID      Name
AXD2     SAM S
AXD2       SAM
SCA4       JIM
SCA4 JIM JONES
ASCQ      JOHN

I need the output to get a unique id and should match the first name only,

  ID  Name
AXD2 SAM S
SCA4   JIM
ASCQ  JOHN

Any suggestions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use drop_duplicates:

out = df.drop_duplicates('ID', ignore_index=True)
print(out)

# Output
     ID   Name
0  AXD2  SAM S
1  SCA4    JIM
2  ASCQ   JOHN
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading