return max value from pandas dataframe as a whole, not based on column or rows

The max of all the values in the DataFrame can be obtained using df.to_numpy().max(), or for pandas < 0.24.0 we use df.values.max():

In [10]: df.to_numpy().max()
Out[10]: 'f'

The max is f rather than 43.0 since, in CPython2,

In [11]: 'f' > 43.0
Out[11]: True

In CPython2, Objects of different types … are
ordered by their type names
. So any str compares as greater than any int since 'str' > 'int'.

In Python3, comparison of strings and ints raises a TypeError.


To find the max value in the numeric columns only, use

df.select_dtypes(include=[np.number]).max()

Leave a Comment