Use the pandas idxmax function. It's straightforward:

>>> import pandas
>>> import numpy as np
>>> df = pandas.DataFrame(np.random.randn(5,3),columns=['A','B','C'])
>>> df
          A         B         C
0  1.232853 -1.979459 -0.573626
1  0.140767  0.394940  1.068890
2  0.742023  1.343977 -0.579745
3  2.125299 -0.649328 -0.211692
4 -0.187253  1.908618 -1.862934
>>> df['A'].idxmax()
3
>>> df['B'].idxmax()
4
>>> df['C'].idxmax()
1
  • Alternatively you could also use numpy.argmax, such as numpy.argmax(df['A']) -- it provides the same thing, and appears at least as fast as idxmax in cursory observations.

  • idxmax() returns indices labels, not integers.

  • Example': if you have string values as your index labels, like rows 'a' through 'e', you might want to know that the max occurs in row 4 (not row 'd').

  • if you want the integer position of that label within the Index you have to get it manually (which can be tricky now that duplicate row labels are allowed).


HISTORICAL NOTES:

  • idxmax() used to be called argmax() prior to 0.11
  • argmax was deprecated prior to 1.0.0 and removed entirely in 1.0.0
  • back as of Pandas 0.16, argmax used to exist and perform the same function (though appeared to run more slowly than idxmax).
  • argmax function returned the integer position within the index of the row location of the maximum element.
  • pandas moved to using row labels instead of integer indices. Positional integer indices used to be very common, more common than labels, especially in applications where duplicate row labels are common.

For example, consider this toy DataFrame with a duplicate row label:

In [19]: dfrm
Out[19]: 
          A         B         C
a  0.143693  0.653810  0.586007
b  0.623582  0.312903  0.919076
c  0.165438  0.889809  0.000967
d  0.308245  0.787776  0.571195
e  0.870068  0.935626  0.606911
f  0.037602  0.855193  0.728495
g  0.605366  0.338105  0.696460
h  0.000000  0.090814  0.963927
i  0.688343  0.188468  0.352213
i  0.879000  0.105039  0.900260

In [20]: dfrm['A'].idxmax()
Out[20]: 'i'

In [21]: dfrm.iloc[dfrm['A'].idxmax()]  # .ix instead of .iloc in older versions of pandas
Out[21]: 
          A         B         C
i  0.688343  0.188468  0.352213
i  0.879000  0.105039  0.900260

So here a naive use of idxmax is not sufficient, whereas the old form of argmax would correctly provide the positional location of the max row (in this case, position 9).

This is exactly one of those nasty kinds of bug-prone behaviors in dynamically typed languages that makes this sort of thing so unfortunate, and worth beating a dead horse over. If you are writing systems code and your system suddenly gets used on some data sets that are not cleaned properly before being joined, it's very easy to end up with duplicate row labels, especially string labels like a CUSIP or SEDOL identifier for financial assets. You can't easily use the type system to help you out, and you may not be able to enforce uniqueness on the index without running into unexpectedly missing data.

So you're left with hoping that your unit tests covered everything (they didn't, or more likely no one wrote any tests) -- otherwise (most likely) you're just left waiting to see if you happen to smack into this error at runtime, in which case you probably have to go drop many hours worth of work from the database you were outputting results to, bang your head against the wall in IPython trying to manually reproduce the problem, finally figuring out that it's because idxmax can only report the label of the max row, and then being disappointed that no standard function automatically gets the positions of the max row for you, writing a buggy implementation yourself, editing the code, and praying you don't run into the problem again.

Answer from ely on Stack Overflow
Top answer
1 of 15
388

Use the pandas idxmax function. It's straightforward:

>>> import pandas
>>> import numpy as np
>>> df = pandas.DataFrame(np.random.randn(5,3),columns=['A','B','C'])
>>> df
          A         B         C
0  1.232853 -1.979459 -0.573626
1  0.140767  0.394940  1.068890
2  0.742023  1.343977 -0.579745
3  2.125299 -0.649328 -0.211692
4 -0.187253  1.908618 -1.862934
>>> df['A'].idxmax()
3
>>> df['B'].idxmax()
4
>>> df['C'].idxmax()
1
  • Alternatively you could also use numpy.argmax, such as numpy.argmax(df['A']) -- it provides the same thing, and appears at least as fast as idxmax in cursory observations.

  • idxmax() returns indices labels, not integers.

  • Example': if you have string values as your index labels, like rows 'a' through 'e', you might want to know that the max occurs in row 4 (not row 'd').

  • if you want the integer position of that label within the Index you have to get it manually (which can be tricky now that duplicate row labels are allowed).


HISTORICAL NOTES:

  • idxmax() used to be called argmax() prior to 0.11
  • argmax was deprecated prior to 1.0.0 and removed entirely in 1.0.0
  • back as of Pandas 0.16, argmax used to exist and perform the same function (though appeared to run more slowly than idxmax).
  • argmax function returned the integer position within the index of the row location of the maximum element.
  • pandas moved to using row labels instead of integer indices. Positional integer indices used to be very common, more common than labels, especially in applications where duplicate row labels are common.

For example, consider this toy DataFrame with a duplicate row label:

In [19]: dfrm
Out[19]: 
          A         B         C
a  0.143693  0.653810  0.586007
b  0.623582  0.312903  0.919076
c  0.165438  0.889809  0.000967
d  0.308245  0.787776  0.571195
e  0.870068  0.935626  0.606911
f  0.037602  0.855193  0.728495
g  0.605366  0.338105  0.696460
h  0.000000  0.090814  0.963927
i  0.688343  0.188468  0.352213
i  0.879000  0.105039  0.900260

In [20]: dfrm['A'].idxmax()
Out[20]: 'i'

In [21]: dfrm.iloc[dfrm['A'].idxmax()]  # .ix instead of .iloc in older versions of pandas
Out[21]: 
          A         B         C
i  0.688343  0.188468  0.352213
i  0.879000  0.105039  0.900260

So here a naive use of idxmax is not sufficient, whereas the old form of argmax would correctly provide the positional location of the max row (in this case, position 9).

This is exactly one of those nasty kinds of bug-prone behaviors in dynamically typed languages that makes this sort of thing so unfortunate, and worth beating a dead horse over. If you are writing systems code and your system suddenly gets used on some data sets that are not cleaned properly before being joined, it's very easy to end up with duplicate row labels, especially string labels like a CUSIP or SEDOL identifier for financial assets. You can't easily use the type system to help you out, and you may not be able to enforce uniqueness on the index without running into unexpectedly missing data.

So you're left with hoping that your unit tests covered everything (they didn't, or more likely no one wrote any tests) -- otherwise (most likely) you're just left waiting to see if you happen to smack into this error at runtime, in which case you probably have to go drop many hours worth of work from the database you were outputting results to, bang your head against the wall in IPython trying to manually reproduce the problem, finally figuring out that it's because idxmax can only report the label of the max row, and then being disappointed that no standard function automatically gets the positions of the max row for you, writing a buggy implementation yourself, editing the code, and praying you don't run into the problem again.

2 of 15
103

You might also try idxmax:

In [5]: df = pandas.DataFrame(np.random.randn(10,3),columns=['A','B','C'])

In [6]: df
Out[6]: 
          A         B         C
0  2.001289  0.482561  1.579985
1 -0.991646 -0.387835  1.320236
2  0.143826 -1.096889  1.486508
3 -0.193056 -0.499020  1.536540
4 -2.083647 -3.074591  0.175772
5 -0.186138 -1.949731  0.287432
6 -0.480790 -1.771560 -0.930234
7  0.227383 -0.278253  2.102004
8 -0.002592  1.434192 -1.624915
9  0.404911 -2.167599 -0.452900

In [7]: df.idxmax()
Out[7]: 
A    0
B    8
C    7

e.g.

In [8]: df.loc[df['A'].idxmax()]
Out[8]: 
A    2.001289
B    0.482561
C    1.579985
๐ŸŒ
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โ€ฆ
๐ŸŒ
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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ select-row-with-maximum-and-minimum-value-in-pandas-dataframe
Select row with maximum and minimum value in Pandas dataframe - GeeksforGeeks
July 11, 2025 - # creating dataframe using DataFrame constructor df = pd.DataFrame(dict1) # the result shows max on # Driver, Points, Age columns. print(df.max()) ... # creating dataframe using DataFrame constructor df = pd.DataFrame(dict1) # Who scored more points ? print(df[df.Points == df.Points.max()]) ... # creating dataframe using DataFrame constructor df = pd.DataFrame(dict1) # what is the maximum age ? print(df.Age.max()) ... # creating dataframe using DataFrame constructor df = pd.DataFrame(dict1) # Which row has maximum age | # who is the oldest driver ?
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-select-row-with-max-value-in-column-from-pandas-groupby-groups
How to Select Row with Max Value in Column from Pandas groupby Groups | Saturn Cloud Blog
October 19, 2023 - Here, we define a function get_max_score() that takes a group as input, finds the row with the maximum value in the โ€˜Scoreโ€™ column using idxmax(), and returns the row.
๐ŸŒ
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 โ€บ 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....
Find elsewhere
๐ŸŒ
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 - View additional explanations, videos, and example problems covering row selection as part of the DISCOVERY course content found here: ... .max() and .min() functions allow us to find the smallest and largest numbers in a column.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ pandas โ€บ ref_df_max.asp
Pandas DataFrame max() Method
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.
๐ŸŒ
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()
๐ŸŒ
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 ...
๐ŸŒ
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 - You can use the following basic syntax to find the max value in each row of a pandas DataFrame: ... This particular syntax creates a new column called max that contains the max value in each row of the DataFrame.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-find-the-maximum-values-in-a-row-with-Pandas-Idxmx-gives-only-the-first-maximum-value-but-in-the-case-of-two-or-more-values-tied-at-maximum-I-want-to-be-able-to-see-all-the-indexes
How can I find the maximum values in a row with Pandas? Idxmx gives only the first maximum value, but in the case of two or more values "...
Answer (1 of 2): Logical indexing is your friend. First, letโ€™s define a dataframe with more than one max value: [code]A = np.arang(10).repeat(2).astype(float) a = pd.DataFrame(A, columns=['one']) [/code]Now, we use logical indexing to find all maxima: [code]a.loc[a['one'] == a['one'].max()] [/...
๐ŸŒ
Moonbooks
en.moonbooks.org โ€บ Articles โ€บ How-to-find-a-maximum-value-in-a-pandas-dataframe-column-
How to find a maximum value in a pandas dataframe column ?
Lets create a dataframe with two ... returns only the first index: 0 ยท To get rows with a max value in the column Age a solution is to do: df[ df['Age'] == df['Age'].max() ] Name Age 0 Ben 43 3 Tom 43 ยท...
๐ŸŒ
Arab Psychology
scales.arabpsychology.com โ€บ psychological scales โ€บ how do i find the max value in a row in pandas?
How Do I Find The Max Value In A Row In Pandas?
September 2, 2024 - To find the maximum value in a row in Pandas, you can use the .max() method. This method will return the highest value in the given row. For example, if you have a dataframe named df, you can use df.max() to return the maximum value in each row of the dataframe.
๐ŸŒ
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 default value for the axis argument is 0. If the axis equals to 0, the max() method will find the max element of each column. On the other hand, if the axis equals to 1, the max() will find the max element of each row.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.idxmax.html
pandas.DataFrame.idxmax โ€” pandas 3.0.2 documentation
By default, it returns the index for the maximum value in each column. >>> df.idxmax() consumption Wheat Products co2_emissions Beef dtype: str ยท To return the index for the maximum value in each row, use axis="columns".