Pandas DataFrame | idxmax method
Start your free 7-days trial now!
Pandas DataFrame.idxmax(~)
method returns the column/row label of the maximum value of each row/column of the source DataFrame. If there are multiple maximums, then the index or label of the first maximum is returned.
Parameters
1. axis
| int
or string
| optional
Whether to return the index of the maximum row-wise or column-wise:
Axis | Description |
---|---|
| Index (row label) of the maximum in each column |
| Column label of the maximum in each row |
By default, axis=0
.
2. skipna
| boolean
| optional
Whether or not to skip NaN
values. By default, skipna=True
.
Return Value
A Series
holding the label of the maximum value of each row or column of the source DataFrame.
Examples
Consider the following DataFrame:
df = pd.DataFrame({"A":[3,4],"B":[6,5]}, index=["a","b"])df
A Ba 3 6b 4 5
The row label of the maximum value for each column is:
df.idxmax()
A bB adtype: object
The column label of the maximum value for each row is:
df.idxmax(axis=1)
a Bb Bdtype: object