Sometimes, we want to find the max of two or more columns with Python Pandas.
In this article, we’ll look at how to find the max of two or more columns with Python Pandas.
How to find the max of two or more columns with Python Pandas?
To find the max of two or more columns with Python Pandas, w ecan use the max
method.
For instance, we write
df["C"] = df[["A", "B"]].max(axis=1)
to add column C to the df
data frame by getting a data frame from with df
‘s columns A and B with df[["A", "B"]]
and call max
on it.
We set axis
to 1 to getc the max of the value in the row between the 2 columns.
Conclusion
To find the max of two or more columns with Python Pandas, w ecan use the max
method.