Python | Pandas dataframe.idxmax()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.idxmax() function returns index of first occurrence of maximum over requested axis. While finding the index of the maximum value across any index, all NA/null values are excluded.
Syntax: DataFrame.idxmax(axis=0, skipna=True)
axis : 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise
skipna : Exclude NA/null values. If an entire row/column is NA, the result will be NA
Returns : idxmax : Series
Example #1: Use
idxmax() function to function to find the index of the maximum value along the index axis.
Now apply the
idxmax() function along the index axis.
If we look at the values in the dataframe, we can verify the result returned by the function. The function returned a pandas series object containing the index of maximum value in each column.
Example #2: Use
idxmax() function to find the index of the maximum value along the column axis. The dataframe contains
The output is a pandas series containing the column label for each row which has the maximum value.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course