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

How do I remove rows on duplicated ids?

I have a pandas dataframe that looks something like this:

ID Value
00001 value 1
00001 value 2
00002 value 3
00003 value 4
00004 value 5
00004 value 6

What I want to do is remove it so that I am left with this:

ID Value
00001 value 1
00002 value 3
00003 value 4
00004 value 5

What’s the best way to achieve this?

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 :

As per my understanding you want to remove duplicates using only first row as criteria, you can using following code

df.drop_duplicates(subset=["ID"], keep='first')
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