0

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?

ZilongShu
  • 3
  • 1

3 Answers3

0

Assuming ID is just a column and not the index

df.drop_duplicates('ID', inplace=True)
maow
  • 2,712
  • 1
  • 11
  • 25
0

df.drop_duplicates(subset='id', keep="first")

ZilongShu
  • 3
  • 1
0

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')