python - Remove duplicates by columns A, keeping the row with the highest value in column B - Stack Overflow

PHOTO EMBED

Mon May 23 2022 11:36:12 GMT+0000 (Coordinated Universal Time)

Saved by @vigneshprince #python

In [12]: df.groupby('A', group_keys=False).apply(lambda x: x.loc[x.B.idxmax()])
Out[12]: 
   A   B
A       
1  1  20
2  2  40
3  3  10
content_copyCOPY

https://stackoverflow.com/questions/12497402/remove-duplicates-by-columns-a-keeping-the-row-with-the-highest-value-in-column