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
If you want the index of the maximum, use idxmax. This is the equivalent of the numpy.ndarray method argmax. ... Axis for the function to be applied on. For Series this parameter is unused and defaults to 0. For DataFrames, specifying axis=None will apply the aggregation across both axes. Added in version 2.0.0. ... Exclude NA/null values when computing the result. ... Include only float, int, boolean columns...
Discussions

Pandas return row with the maximum value of a column
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 time figuring out how to return the whole row with the maximum value in ... More on community.dataquest.io
🌐 community.dataquest.io
5
0
January 30, 2020
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
What is the method to find the maximum value in each row of a dataframe? - Python - Data Science Dojo Discussions
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 find the column with the highest number of row-wise ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
3
0
February 22, 2023
Merging four similar Pandas DataFrames and keeping the maximum rows
Can you clarify what you mean by "...keep only the rows with the maximum in Col5."? Do you mean that the resulting dataframe will only have 4 rows (the max Col5 row from each of the children dataframes)? More on reddit.com
🌐 r/learnpython
20
89
December 23, 2020
🌐
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 - 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.
🌐
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 - Q1: How do I find the maximum value of a specific column? If you’re only interested in one column, it’s super straightforward. Just use: import pandas as pd df = pd.DataFrame({ 'A': [1, 4, 7], 'B': [2, 5, 8], 'C': [3, 6, 9] }) # Finding the maximum value in column 'A' print(df['A'].max()) # Output: 7
🌐
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)
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.idxmax.html
pandas.DataFrame.idxmax — pandas 3.0.2 documentation
>>> df = pd.DataFrame( ... { ... ... co2_emissions Pork 10.51 37.20 Wheat Products 103.11 19.66 Beef 55.48 1712.00 · By default, it returns the index for the maximum value in each column....
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas dataframe max() function
Pandas DataFrame max() Function - Spark By {Examples}
December 6, 2024 - In pandas, you can find the maximum value in a DataFrame using the max() function. This function can be applied to either rows or columns. In this
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.sort_values.html
pandas.DataFrame.sort_values — pandas 3.0.2 documentation
For DataFrames, this option is only applied when sorting on a single column or label. na_position{‘first’, ‘last’}, default ‘last’ · Puts NaNs at the beginning if first; last puts NaNs at the end. ... If True, the resulting axis will be labeled 0, 1, …, n - 1. ... Apply the key function to the values before sorting.
🌐
Reddit
reddit.com › r/learnpython › pandas: get the max value of a group only if the value satisfies given conditions
r/learnpython on Reddit: Pandas: Get the max value of a group ONLY if the value satisfies given conditions
September 20, 2022 -

I have a huge datatset.

The data is grouped by col, row, year, no, potveg, and total. I am trying to get the maximum value of the 'total' column in each specific group year ONLY if its 'possible' value is TRUE. If the max 'total' value is FALSE, then get the second max value, and so on.

If all the values of the 'possible' column in a specific year group = False, then I want to pick the max out of the False so that I don't skip any years.

i.e., for the dataset below:

col	row	year	no	potveg	total	possible
                        						
-125	42.5	2015	1	9	697.3	FALSE
-125	42.5	2015	2	13	535.2	TRUE
-125	42.5	2015	3	15	82.3	TRUE
-125	42.5	2016	1	9	907.8	TRUE
-125	42.5	2016	2	13	137.6	FALSE
-125	42.5	2016	3	15	268.4	TRUE
-125	42.5	2017	1	9	961.9	FALSE
-125	42.5	2017	2	13	74.2	TRUE
-125	42.5	2017	3	15	248	TRUE
-125	42.5	2018	1	9	937.9	TRUE
-125	42.5	2018	2	13	575.6	TRUE
-125	42.5	2018	3	15	215.5	FALSE
-135	70.5	2015	1	8	697.3	FALSE
-135	70.5	2015	2	10	535.2	TRUE
-135	70.5	2015	3	19	82.3	TRUE
-135	70.5	2016	1	8	907.8	TRUE
-135	70.5	2016	2	10	137.6	FALSE
-135	70.5	2016	3	19	268.4	TRUE
-135	70.5	2017	1	8	961.9	FALSE
-135	70.5	2017	2	10	74.2	TRUE
-135	70.5	2017	3	19	248	TRUE
-135	70.5	2018	1	8	937.9	TRUE
-135	70.5	2018	2	10	575.6	TRUE
-135	70.5	2018	3	19	215.5	FALSE
-135	70.5	2019	1	8	937.9	FALSE
-135	70.5	2019	2	10	575.6	FALSE
-135	70.5	2019	3	19	215.5	FALSE

The output would be:

col	row	year	no	potveg	total	possible
-125	42.5	2015	2	13	535.2	TRUE
-125	42.5	2016	1	9	907.8	TRUE
-125	42.5	2017	3	15	248	TRUE
-125	42.5	2018	1	9	937.9	TRUE
-135	70.5	2015	2	10	535.2	TRUE
-135	70.5	2016	1	8	907.8	TRUE
-135	70.5	2017	3	19	248	TRUE
-135	70.5	2018	1	8	937.9	TRUE
-135	70.5	2019	1	8	937.9	FALSE

I have tried

# Separate out the true and false possibilities by grouping by ['col','row','year','possible']
#  and getting the idxmax for column total. At the end, we sort the result on possible in descending order.
#  This  puts all idxmax values (now in total) with True in possible first.

idx = df.groupby(['col','row','year','possible'], as_index=False)['total']\
    .idxmax().sort_values('possible', ascending=False)['total']

#we then apply a second groupby, this time only on['col', 'row', 'year'] and simply get the first.

result = df.iloc[idx].groupby(['col', 'row', 'year']).first()
orig_index = df.set_index(['col', 'row', 'year']).index.drop_duplicates()

#re-establishing the original order by using df.reindex based on the original df 
# with index there set to ['col','row','year'] and getting rid of the duplicates first.

result_reordered = result.reindex(orig_index)

But I am still getting some years where the max value is not picked resulting in duplicates.

🌐
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 ?
import pandas as pd data = {'Name':['Ben','Anna','Zoe','Tom','John','Steve','Becky','Bob'], 'Age':[20,27,20,43,30,20,22,21]} df = pd.DataFrame(data) df ... It is also possible to find the index corresponding to the max value in the column Age using the pandas function called idxmax
🌐
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 ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.html
pandas.DataFrame — pandas 3.0.2 documentation
Alignment is done on Series/DataFrame inputs. If data is a list of dicts, column order follows insertion-order. ... Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided. ... Column labels to use for resulting frame when data does not have them, defaulting to RangeIndex(0, 1, 2, …, n).
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.loc.html
pandas.DataFrame.loc — pandas 3.0.2 documentation
>>> shuffled_df = df.loc[["viper", "cobra", "sidewinder"]] >>> df.loc[:] += shuffled_df >>> df max_speed shield cobra 60 20 viper 0 10 sidewinder 0 0 · Getting values on a DataFrame with an index that has integer labels ... >>> df = pd.DataFrame( ... [[1, 2], [4, 5], [7, 8]], ... index=[7, 8, 9], ... columns=["max_speed", "shield"], ...
🌐
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. We then apply this function to each group using groupby() to get the maximum scores for each group. ... The final method we will explore is using groupby() and transform(). transform() applies a function to each group and returns a DataFrame with the same shape as the original DataFrame.
🌐
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 - #add new column that contains max ... 6 7.0 14.0 10 14.0 7 22.0 10.0 11 22.0 · The column called max now contains the max value in each row for the points and rebounds columns only....
🌐
pandas
pandas.pydata.org › Pandas_Cheat_Sheet.pdf pdf
Creating DataFrames
... Sets the title of the graph. ... Plot a line graph for the DataFrame. ... Plot a scatter graph of the DataFrame. ... Plot a histogram of the DataFrame. ... Plot a pie chart of the DataFrame. ... Set the display.max_rows option to 20. ... Controls how column headers are justified.