Pandas DataFrame idxmax() Method
Example
Return the index of the row with the highest sales, and the index of the row with the highest age:
import pandas as pd
data = {
"sales": [23, 34, 56],
"age": [50, 40, 30]
}
df = pd.DataFrame(data)
print(df.idxmax())
Try it Yourself »
Definition and Usage
The idxmax()
method returns a Series with
the index of the maximum value for each column.
By specifying the column axis (axis='columns'
), the
idxmax()
method returns a Series with the index of the maximum value for each row.
Syntax
dataframe.idxmax(axis, skipna)
Parameters
The parameters are keyword arguments.
Parameter | Value | Description |
---|---|---|
axis | 0 |
Optional, Which axis to check, default 0. |
skipna | True |
Optional, default True. Specifies whether to skip NULL values or not. |
Return Value
A Series with the indexes of the rows/columns with the highest values.