Get max value from row of a dataframe in python [duplicate]

Use max with axis=1:

df = df.max(axis=1)
print (df)
0    2.0
1    3.2
2    8.8
3    7.8
dtype: float64

And if need new column:

df['max_value'] = df.max(axis=1)
print (df)
     a    b     c  max_value
0  1.2  2.0  0.10        2.0
1  2.1  1.1  3.20        3.2
2  0.2  1.9  8.80        8.8
3  3.3  7.8  0.12        7.8

Leave a Comment