1

I have a ufc dataset i am practicing on and want to create a dataframe with all fighters and their atributes. It is currently in order of most recent fight back to the start of the promotion.

I want to remove all occurances of each fighter other than their most recent.

e.g.

index, fighter, height, age, wins, losses
0, mcgregor, 165, 31, 14,5
1, porier, 165, 30, 21, 6
2, Ferguson, 180, 38, 28, 4
3, mcgregor, 165, 30, 14, 4 <- remove this row.

thanks for any help.

1 Answers1

2

You can sort by age (highest on top) and drop_duplicates:

df.sort_values(by='age', ascending=False).drop_duplicates(subset='fighter')
mozway
  • 194,879
  • 13
  • 39
  • 75