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()
Hi the simplest answer is the following. Answer:
df.max().max()
Explanation: series = df.max()
give you a Series containing the maximum values for each column.
Therefore series.max()
gives you the maximum for the whole dataframe.
:) best answers are usually the simplest
An alternative way:
df.melt().value.max()
Essentially melt()
transforms the DataFrame into one long column.