pandas - Python Dataframe select rows based on max values in one of the columns -


i have dataframe in python (many rows, 2 columns). want modify df unique value in column 1 based on largest value in column 2 (column 2 sorted in ascending order if helps). write loop prefer 1 or 2 line solution. thanks.

ex.

id         value 100       11 100       14 100       16 200       10 200       20 200       30 300       45 400        0 400       25 

desired result

100       16 200       30 300       45 400       25 

you want groupby on 'a' column , index of max value using idxmax , use these indices index orig df:

in [12]: df.loc[df.groupby('a')['b'].idxmax()]  out[12]:        b 2  100  16 5  200  30 6  300  45 8  400  25 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -