Assuming df has a unique index, this gives the row with the maximum value:

In [34]: df.loc[df['Value'].idxmax()]
Out[34]: 
Country        US
Place      Kansas
Value         894
Name: 7

Note that idxmax returns index labels. So if the DataFrame has duplicates in the index, the label may not uniquely identify the row, so df.loc may return more than one row.

Therefore, if df does not have a unique index, you must make the index unique before proceeding as above. Depending on the DataFrame, sometimes you can use stack or set_index to make the index unique. Or, you can simply reset the index (so the rows become renumbered, starting at 0):

df = df.reset_index()
Answer from unutbu on Stack Overflow
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.max.html
pandas.DataFrame.max โ€” pandas 3.0.2 documentation
Value containing the calculation referenced in the description. ... Return the sum. ... Return the minimum. ... Return the maximum. ... Return the index of the minimum. ... Return the index of the maximum. ... Return the sum over the requested axis. ... Return the minimum over the requested axis. ... 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.
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ find-maximum-values-position-in-columns-and-rows-of-a-dataframe-in-pandas
Find maximum values & 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. ...
๐ŸŒ
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
Find elsewhere
๐ŸŒ
Dataquest Community
community.dataquest.io โ€บ q&a โ€บ dq courses
Pandas return row with the maximum value of a column - DQ Courses - Dataquest Community
January 30, 2020 - Iโ€™m trying to figure out how to return the row of a pandas dataframe with the maximum value in a certain column. I know that to find the maximum value in a column I use: df['columnName'].max() But Iโ€™m having a hard tiโ€ฆ
๐ŸŒ
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.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-pandas-find-the-maximum-value-of-a-column-and-return-its-corresponding-row-values
Python Pandas โ€“ Find the maximum value of a column and return its corresponding row values
August 27, 2023 - Maximum value of column x and its corresponding row values: x 7 y 5 z 5 Name: 2, dtype: int64 ยท import pandas as pd df = pd.DataFrame( { "x": [5, 2, 7, 0], "y": [4, 7, 5, 1], "z": [9, 3, 5, 1] } ) # Check maximum for all columns for col in ["x", "y", "z"]: max_row = df.loc[df[col].idxmax()] print(f"Column '{col}' maximum (value={max_row[col]}) at index {df[col].idxmax()}:") print(max_row) print()
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
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 - df.iloc[] gets the column index as input here column index 1 is passed which is 2nd column (โ€œAgeโ€ column), maximum value of the 2nd column is calculated using max() function as shown.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-get-the-max-element-of-a-pandas-dataframe-rows-columns-entire-dataframe
How to Get the Max Element of a Pandas DataFrame - Rows, Columns, Entire DataFrame
July 19, 2022 - The df we've constructed now contains ... of each column, each row or the entire DataFrame. To find the maximum element of each column, we call the max() method of the DataFrame class, which returns a Series of column names and their largest values:...
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: return row with max value in particular column
Pandas: Return Row with Max Value in Particular Column
July 11, 2022 - This tutorial explains how to return the row that contains the max value in a particular column, including examples.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-get-the-maximum-value-from-the-pandas-dataframe-in-python
How to Get the maximum value from the Pandas dataframe in Python? - GeeksforGeeks
November 28, 2021 - We can get the minimum value by using the min() function Syntax: dataframe.min(axis) where,ร‚ axis=0 specifies columnaxis=1 specifies rowGet minimum value in dataframe row To get the minimum value in a ... In this article, we will explore various methods to retrieve cell values from a Pandas DataFrame in Python. Pandas provides several functions to access specific cell values, either by label or by position.Get value from a cell of Dataframe using loc() functionThe .loc[] function in Pandas allows you
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
What is the method to find the maximum value in each row of a dataframe? - Python - Data Science Dojo Discussions
February 22, 2023 - I wanted to get a name of a column and the only method I know to do this using the method idmax() which is used in Pandas to find the column with the maximum value in each row of the DataFrame and then count the occurrences of each column to ...
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)
๐ŸŒ
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.