0

I'm learning Pandas and stumble around finding the entire row of Data frame having maximum of one column

      A           B
0     Fruits     122
1     Veggies    23
2     Eggs       223

How to get the entire row where B is maximum

This is what I tried: df['B'].max(), however this just gives me the index i.e. 2. How to get the entire row such as Eggs 223. Can someone suggest one liner pls

user4943236
  • 5,914
  • 11
  • 27
  • 40

1 Answers1

4

You could use argmax to get index of the maximum value and then pass it to iloc to get your row:

In [195]: df.iloc[df.B.argmax()]
Out[195]:
A    Eggs
B     223
Name: 2, dtype: object

Or if you prefer list you could use tolist method:

In [196]: df.iloc[df.B.argmax()].tolist()
Out[196]: ['Eggs', 223]
Anton Protopopov
  • 30,354
  • 12
  • 88
  • 93