-1

Here's my dtaset

Id   Website    Rank
1    facebook   25
2    facebook   5
3    line       9

What I want is only keep the lowest rank

Id   Website    Rank
2    facebook   5
3    line       9
not a robot
  • 2,436
  • 1
  • 10
  • 24
Nabih Bawazir
  • 5,275
  • 6
  • 29
  • 53

1 Answers1

1

Try this

df = pd.DataFrame({'Id': [1, 2, 3],
                   'Website': ['facebook', 'facebook', 'line'],
                   'Rank': [25, 5, 9]})
# index the min ranks of each website
df.loc[df.groupby('Website')['Rank'].idxmin()]
   Id   Website  Rank
1   2  facebook     5
2   3      line     9
not a robot
  • 2,436
  • 1
  • 10
  • 24