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.