Pandas DataFrame | idxmin method
Start your free 7-days trial now!
Pandas DataFrame.idxmin(~)
method returns the column/row label of the minimum value of each row/column of the source DataFrame. If there are multiple minimums, then the index or label of the first minimum 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 minimum in each column |
| Column label of the minimum of 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 minimum 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 minimum value for each column is:
df.idxmin()
A aB bdtype: object
The column label of the minimum value for each row is:
df.idxmin(axis=1)
a Ab Adtype: object