Find the maximum position in columns and rows in Pandas

Pandas dataframe.idxmax() method returns the index of the first occurrence of maximum over the requested axis. While finding the index of the maximum value across any index, all NA/null values are excluded. 

Find the row index which has the maximum value

It returns a series containing the column names as index and row as index labels where the maximum value exists in that column.

Python3




# find the index position of maximum
# values in every column
maxValueIndex = df.idxmax()
 
print("Maximum values of columns are at row index position :")
print(maxValueIndex)


Output: 

Find the column name which has the maximum value

It returns a series containing the rows index labels as index and column names as values where the maximum value exists in that row.

Python3




# find the column name of maximum
# values in every row
maxValueIndex = df.idxmax(axis=1)
 
print("Max values of row are at following columns :")
print(maxValueIndex)


Output:



Find maximum values & position in columns and rows of a Dataframe in Pandas

In this article, we are going to discuss how to find the maximum value and its index position in columns and rows of a Dataframe.

Similar Reads

Create Dataframe to Find max values & position of columns or rows

Python3 import numpy as np import pandas as pd # List of Tuples matrix = [(10, 56, 17),           (np.NaN, 23, 11),           (49, 36, 55),           (75, np.NaN, 34),           (89, 21, 44)           ] # Create a DataFrame abc = pd.DataFrame(matrix, index=list('abcde'), columns=list('xyz'))   # output abc...

Find maximum values in columns and rows in Pandas

...

Find the maximum position in columns and rows in Pandas

Pandas dataframe.max() method finds the maximum of the values in the object and returns it. If the input is a series, the method will return a scalar which will be the maximum of the values in the series. If the input is a Dataframe, then the method will return a series with a maximum of values over the specified axis in the Dataframe. The index axis is the default axis taken by this method....

Contact Us