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)
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ pandas โ€บ ref_df_max.asp
Pandas DataFrame max() Method
By specifying the column axis (axis='columns'), the max() method searches column-wise and returns the maximum value for each row. dataframe.max(axis, skipna, level, numeric_only, kwargs) The axis, skipna, level, numeric_only parameters are keyword ...
๐ŸŒ
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 maximum value in a given column, multiple columns, or the entire dataframe.
๐ŸŒ
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 - This tutorial explains how to find the max value across multiple columns in a pandas DataFrame, including several examples.
๐ŸŒ
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 - The nlargest and nsmallest functions allow us to find the rows that have the largest or smallest values for a specific columns. For example, we may want the three movies with the largest domestic box office sales: 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, "international box office": 138500000},
Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas find row values for column maximal
Pandas Find Row Values for Column Maximal - Spark By {Examples}
November 25, 2024 - In Pandas, you can find the row values for the maximum value in a specific column using the idxmax() function along with the column selection. You can
๐ŸŒ
DataScience Made Simple
datasciencemadesimple.com โ€บ home โ€บ max() โ€“ maximum value of column in python pandas
max() - maximum value of column in python pandas - DataScience Made Simple
December 24, 2020 - How to get Column wise maximum value of all the column. ... import pandas as pd import numpy as np #Create a DataFrame d = { 'Name':['Alisa','Bobby','jodha','jack','raghu','Cathrine', 'Alisa','Bobby','kumar','Alisa','Alex','Cathrine'], 'Age':[26,24,23,22,23,24,26,24,22,23,24,24], 'Score':[85,63,55,74,31,77,85,63,42,62,89,77]} df = pd.DataFrame(d,columns=['Name','Age','Score']) df
๐ŸŒ
thisPointer
thispointer.com โ€บ home โ€บ pandas โ€บ pandas: find maximum values & position in columns or rows of a dataframe
Pandas: Find maximum values & position in columns or rows of a Dataframe - thisPointer
November 7, 2019 - In this article we will discuss how to find maximum value in rows & columns of a Dataframe and also itโ€™s index position. Pythonโ€™s Pandas Library provides a member function in Dataframe to find the maximum value along the axis i.e.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: how to find the max value in each row
Pandas: How to Find the Max Value in Each Row
February 16, 2023 - The column called max now contains the max value in each row for the points and rebounds columns only. Note: You can find the complete documentation for the pandas max() function here.
๐ŸŒ
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
๐ŸŒ
Python Examples
pythonexamples.org โ€บ pandas-dataframe-maximum-max
Pandas DataFrame - Maximum Value - max() - Exmaples
The max() method calculates the highest mark in each column, representing the maximum value for each subject. The output displays the maximum value of each subject's marks. DataFrame ---------- physics chemistry algebra 0 68 84 78 1 74 56 88 2 77 73 82 3 78 69 87 Maximum Value ------ physics ...
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ finding-the-column-name-corresponding-to-the-largest-value-in-a-pandas-dataframe
Finding the Column Name Corresponding to the Largest Value in a Pandas DataFrame | Saturn Cloud Blog
December 25, 2023 - This will output: ['A', 'B'], as both columns โ€˜Aโ€™ and โ€˜Bโ€™ contain the maximum value of 5. Error: If the DataFrame contains non-numeric data, the idxmax() and argmax() functions may raise an error.
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ understanding-pandas-max-a6c077525d42
Understanding pandas max(). If you think you need to spend $2,000โ€ฆ | by whyamit404 | Medium
February 26, 2025 - 1 or columns โ†’ Finds the max for each row. You can switch between columns and rows easily using this. ... True โ†’ Ignores NaN (keeps calculations clean). False โ†’ Includes NaN, which can mess up your max values.
๐ŸŒ
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 - We can find also return the entire row that corresponds to the max value in a certain column. For example, the following syntax returns the entire row that corresponds to the player with the max points: #return entire row of player with the max points df[df['points']==df['points'].max()] player points assists rebounds 4 E 27 5 6.0 ยท If multiple rows have the same max value, each row will be returned.