0

I have a data frame similar to:

    a   b   c  d
a   1   2   3  4 
b   5   6   7  8
c   9   10  11 12
d   13  14  15 16

How do I find the maximum value in the data frame, along with its corresponding column and row name? For example I'd like to return: (d,d,16) I'd also like to do the same of the minimum value, so return: (a,a,1)

rpanai
  • 12,515
  • 2
  • 42
  • 64
Steel
  • 507
  • 4
  • 13

1 Answers1

0

As a priori the max and the min are not unique you can play from

import pandas as pd
import numpy as np

df = pd.DataFrame(np.arange(6).reshape(2,3))

#show max
df[df==df.max().max()]

#show min
df[df==df.min().min()]
rpanai
  • 12,515
  • 2
  • 42
  • 64
  • df[df==df.max().max()] just returns the full data frame with all NaN values except for the max which is shown somewhere in the data frame. I am still unsure how to also get the corresponding column and row values for that max cell – Steel Mar 01 '19 at 21:57
  • You mean the row number and the column name. As I stated it's not meant to be a full answer. But from there you can use https://stackoverflow.com/a/37755016/4819376 – rpanai Mar 01 '19 at 22:21
  • You mean the row number and the column name. As I stated it's not meant to be a full answer. But from there you can use https://stackoverflow.com/a/37755016/4819376 – rpanai Mar 01 '19 at 22:22