-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
cottontail
  • 10,268
  • 18
  • 50
  • 51
Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70

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
cottontail
  • 10,268
  • 18
  • 50
  • 51