series = df.max()
give you a Series containing the maximum values for each column. series.max()
gives you the maximum for the whole dataframe.numeric_only
is required when strings are involved; as @unutbu's answer points out, the result for the OP's question would otherwise be f
in python 2 and TypeError
in python 3.
An alternative way:
df.melt().value.max()
Essentially melt()
transforms the DataFrame into one long column.
using numpy max
np.max(df.values)
or
np.nanmax(df.values)
or in pandas
df.values.max()
For the max, check the previous answer...For the max of the values use e.g.:
val_cols = [c for c in df.columns if c.startswith('val')]print df[val_cols].max()
Max can be found in these two steps:
maxForRow = allData.max(axis=0) #max for each rowglobalMax = maxForRow.max(); #max across all rows
This answer is probably best for the general case, but if you need speed, and your values are limited to known columns, specifying your columns first will use less cpu cycles. For example:
df[['value1', 'value2']].max(numeric_only=True).max()
You can drop the numeric_only
if the specified columns are known to contain only numbers.