You can get the maximum like this:

>>> import pandas as pd
>>> df = pd.DataFrame({"A": [1,2,3], "B": [-2, 8, 1]})
>>> df
   A  B
0  1 -2
1  2  8
2  3  1
>>> df[["A", "B"]]
   A  B
0  1 -2
1  2  8
2  3  1
>>> df[["A", "B"]].max(axis=1)
0    1
1    8
2    3

and so:

>>> df["C"] = df[["A", "B"]].max(axis=1)
>>> df
   A  B  C
0  1 -2  1
1  2  8  8
2  3  1  3

If you know that "A" and "B" are the only columns, you could even get away with

>>> df["C"] = df.max(axis=1)

And you could use .apply(max, axis=1) too, I guess.

Answer from DSM on Stack Overflow
Top answer
1 of 4
320

You can get the maximum like this:

>>> import pandas as pd
>>> df = pd.DataFrame({"A": [1,2,3], "B": [-2, 8, 1]})
>>> df
   A  B
0  1 -2
1  2  8
2  3  1
>>> df[["A", "B"]]
   A  B
0  1 -2
1  2  8
2  3  1
>>> df[["A", "B"]].max(axis=1)
0    1
1    8
2    3

and so:

>>> df["C"] = df[["A", "B"]].max(axis=1)
>>> df
   A  B  C
0  1 -2  1
1  2  8  8
2  3  1  3

If you know that "A" and "B" are the only columns, you could even get away with

>>> df["C"] = df.max(axis=1)

And you could use .apply(max, axis=1) too, I guess.

2 of 4
55

@DSM's answer is perfectly fine in almost any normal scenario. But if you're the type of programmer who wants to go a little deeper than the surface level, you might be interested to know that it is a little faster to call numpy functions on the underlying .to_numpy() (or .values for <0.24) array instead of directly calling the (cythonized) functions defined on the DataFrame/Series objects.

For example, you can use ndarray.max() along the first axis.

# Data borrowed from @DSM's post.
df = pd.DataFrame({"A": [1,2,3], "B": [-2, 8, 1]})
df
   A  B
0  1 -2
1  2  8
2  3  1

df['C'] = df[['A', 'B']].values.max(1)
# Or, assuming "A" and "B" are the only columns, 
# df['C'] = df.values.max(1) 
df

   A  B  C
0  1 -2  1
1  2  8  8
2  3  1  3 

If your data has NaNs, you will need numpy.nanmax:

df['C'] = np.nanmax(df.values, axis=1)
df

   A  B  C
0  1 -2  1
1  2  8  8
2  3  1  3 

You can also use numpy.maximum.reduce. numpy.maximum is a ufunc (Universal Function), and every ufunc has a reduce:

df['C'] = np.maximum.reduce(df['A', 'B']].values, axis=1)
# df['C'] = np.maximum.reduce(df[['A', 'B']], axis=1)
# df['C'] = np.maximum.reduce(df, axis=1)
df

   A  B  C
0  1 -2  1
1  2  8  8
2  3  1  3

np.maximum.reduce and np.max appear to be more or less the same (for most normal sized DataFrames)—and happen to be a shade faster than DataFrame.max. I imagine this difference roughly remains constant, and is due to internal overhead (indexing alignment, handling NaNs, etc).

The graph was generated using perfplot. Benchmarking code, for reference:

import pandas as pd
import perfplot

np.random.seed(0)
df_ = pd.DataFrame(np.random.randn(5, 1000))

perfplot.show(
    setup=lambda n: pd.concat([df_] * n, ignore_index=True),
    kernels=[
        lambda df: df.assign(new=df.max(axis=1)),
        lambda df: df.assign(new=df.values.max(1)),
        lambda df: df.assign(new=np.nanmax(df.values, axis=1)),
        lambda df: df.assign(new=np.maximum.reduce(df.values, axis=1)),
    ],
    labels=['df.max', 'np.max', 'np.maximum.reduce', 'np.nanmax'],
    n_range=[2**k for k in range(0, 15)],
    xlabel='N (* len(df))',
    logx=True,
    logy=True)
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.max.html
pandas.DataFrame.max — pandas 3.0.2 documentation
Return the maximum over the requested axis. ... Return the index of the minimum over the requested axis. ... Return the index of the maximum over the requested axis.
Discussions

pandas - How do I find pairwise maximum of multiple rows in a column using python? - Data Science Stack Exchange
I have a column with float values. The column has 300 rows. I want to get the pairwise max of each row with the row below it. For example: if my column has 2, 25, 1, 24 as row values, I want to fin... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
June 8, 2021
Python Pandas add column for row-wise max value of selected columns - Stack Overflow
1477 How to drop rows of Pandas DataFrame whose value in a certain column is NaN More on stackoverflow.com
🌐 stackoverflow.com
Finding max of the difference between two columns in dataframe
Your suggested syntax doesn't give the result your question implies: it gives you the rows which have the maximum difference. If you just want the index, you can use idxmax: (df["2021"] - df["2022"]).idxmax() and if you did want the matching row, you can just wrap that in a loc: df.loc[(df["2021"] - df["2022"]).idxmax()] More on reddit.com
🌐 r/learnpython
3
1
October 13, 2023
Pandas: Get the max value of a group ONLY if the value satisfies given conditions
Can't you just: sort by: , Possible, Total keep the last record for each ? Sorting by keeps your groups together. Sorting by Possible puts False before True in each group, so if you have True values, keeping the last will ensure you pick a True. Then sorting by Total ensures the last value is the largest of the Trues, or if all Falses, the largest of the Falses. (Edit: typo) More on reddit.com
🌐 r/learnpython
6
1
September 20, 2022
🌐
Reddit
reddit.com › r/learnpython › finding max of the difference between two columns in dataframe
r/learnpython on Reddit: Finding max of the difference between two columns in dataframe
October 13, 2023 -

Hi folks, I would like to find the index of the row that contains the maximum value between the two columns. This is what I have:

df = pd.DataFrame({"2021":[5, 8, 12, 9, 5, 3], 
               "2022":[11, 4, 8, 7, 3, 2]}) 

df1 = df.iloc[df[(df["2021"] - df["2022"]) == (df["2021"] - df["2022"]).max()].index]

It looks kind of messy. I am not sure if this is the best way to get the answer. Do you have simpler recommendations? Please advise. Thanks.

🌐
Statology
statology.org › home › pandas: how to find max value across multiple columns
Pandas: How to Find Max Value Across Multiple Columns
August 3, 2022 - The new column titled max_points_rebs now contains the max value across the points and rebounds columns for each row in the DataFrame. The following tutorials explain how to perform other common tasks in pandas: Pandas: How to Move Column to Front of DataFrame Pandas: How to Check if Column Contains String Pandas: How to Add Empty Column to DataFrame
🌐
W3Schools
w3schools.com › python › pandas › ref_df_max.asp
Pandas DataFrame max() Method
Return the highest value for each column: import pandas as pd data = [[10, 18, 11], [13, 15, 8], [9, 20, 3]] df = pd.DataFrame(data) print(df.max()) Try it Yourself » · The max() method returns a Series with the maximum value of each column.
🌐
IncludeHelp
includehelp.com › python › find-the-max-of-two-or-more-columns-with-pandas.aspx
Find the max of two or more columns with pandas?
September 23, 2023 - To find the maximum value between two or more columns, we will use the column names and find their difference by using the sub() method also we will find the absolute values by using abs() method. ... # Importing pandas package import pandas as pd # Importing reduce function from functools ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-maximum-values-position-in-columns-and-rows-of-a-dataframe-in-pandas
Find maximum values &amp; position in columns and rows of a Dataframe in Pandas - GeeksforGeeks
July 15, 2025 - If the input is a Dataframe, then ... this method. To find the maximum value of each column, call the max() method on the Dataframe object without taking any argument....
🌐
Data Science Discovery
discovery.cs.illinois.edu › guides › DataFrame-Row-Selection › finding-min-and-max
Finding Minimum and Maximum Values in a DataFrame Column - Data Science Discovery
August 10, 2022 - .max() and .min() functions allow us to find the smallest and largest numbers in a column. Make sure to specify the column in brackets before applying the function. Note: this only works for columns of integer or float dtypes — not strings. import pandas as pd\n&nbsp;\n#Creates a DataFrame of "movie", "release date", "domestic gross", "worldwide gross", "personal rating", and "international box office" columns\ndf = pd.DataFrame([\n {"movie": "The Truman Show", "release date": "1996-06-05", "domestic box office": 125618201, "worldwide box office": 264118201, "personal rating": 10, "internati
🌐
Easy Tweaks
easytweaks.com › pandas-max-two-multiple-columns
How to find the max of two or more columns in Pandas?
July 26, 2022 - Skip to content · BECOMING MORE EFFICIENT WITH TECH · HELPING TO REDUCE BUSY WORK SO YOU CAN FOCUS ON STUFF THAT MATTERS · Check out our latest posts: · How to change the default Email Account in Gmail and Outlook · How to fix Windows 11 Not detecting Bluetooth headset · How to fix Microsoft ...
🌐
Data Science Parichay
datascienceparichay.com › home › blog › pandas – get max value in one or more columns
Pandas - Get max value in one or more columns - Data Science Parichay
February 14, 2023 - You can use the pandas max() function to get the max value in a given column, multiple columns or the entire dataframe.
🌐
Statology
statology.org › home › how to find the max value of columns in pandas
How to Find the Max Value of Columns in Pandas
July 29, 2020 - #find max of points and rebounds columns df[['rebounds', 'points']].max() rebounds 10.0 points 27.0 dtype: float64
🌐
Saturn Cloud
saturncloud.io › blog › how-to-find-the-max-of-two-or-more-columns-with-pandas
How to Find the Max of Two or More Columns with Pandas | Saturn Cloud Blog
October 4, 2023 - The axis=1 parameter tells Pandas to look for the maximum value across the rows rather than the columns. The max_value variable contains the resulting maximum value. In this article, we have explored how to use Pandas to find the maximum value ...
🌐
Arab Psychology
scales.arabpsychology.com › psychological scales › how to find the max value of columns in pandas
How To Find The Max Value Of Columns In Pandas
November 15, 2023 - In Pandas, you can find the maximum value of any column by using the max() method. This method takes the column as an argument and returns the maximum value
🌐
Intellipaat
intellipaat.com › home › blog › python pandas add a column for row-wise max value of selected columns
Python Pandas add a column for row-wise max value of selected columns - Intellipaat
February 3, 2026 - You can use the df.max(axis = 1) function as it is very efficient, but the numpy.maximum.reduce() is better when you are working with larger datasets. If you need flexibility, you can use apply() for complex operations.