Mode value with multiple different inputs - select maximum

please I have df as follow:

Column Value1 Value2 Value3 Value4 Value5  Mode
first  1      1      2      1      NaN     1
second NaN    NaN    2      2      2       2
third  NaN    NaN    NaN    2      1       1

If I use df.mode(), then in the last row I will get 1, which is minimum from 1 and 2. What is the best way to get max value in case I have different values in the row and therefore there is no mode value?

Thanks


mode returns a DataFrame with all modes, you can apply max to get the max value:

df['Mode'] = df.filter(like='Value').mode(axis=1).max(axis=1)

output:

   Column  Value1  Value2  Value3  Value4  Value5  Mode
0   first     1.0     1.0     2.0       1     NaN   1.0
1  second     NaN     NaN     2.0       2     2.0   2.0
2   third     NaN     NaN     NaN       2     1.0   2.0