Issue
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?
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')
Answered By - Kartik Thakkar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.