Python ProgrammingPython Programming

Pandas find row where values for column is maximum

Find row where values for column is maximum:

import pandas as pd

df = pd.DataFrame([[10, 20, 30, 40], [7, 14, 21, 28], [55, 15, 8, 12]],
                  columns=['Apple', 'Orange', 'Banana', 'Pear'],
                  index=['Basket1', 'Basket2', 'Basket3'])

print(df.ix[df['Apple'].idxmax()])


C:\pandas>python example.py
Apple     55
Orange    15
Banana     8
Pear      12
Name: Basket3, dtype: int64
 
C:\pandas>