Column-wise minima
Identify the row label associated with the lowest measurement in every column.
Pandas · Module
DataFrame.idxmin returns the label of the first minimum in each column or row. It skips missing values by default and can restrict processing to numeric columns.
Call this DataFrame method to obtain labels—not minimum values—for the first minimum along columns or rows. Missing values are skipped by default, and numeric_only can restrict the operation to floating-point, integer, and Boolean columns.
DataFrame.idxmin(axis=0, skipna=True, numeric_only=False)| Name | Type | Description |
|---|---|---|
axis | 0 or “index”, 1 or “columns”; default 0 | Axis to reduce: 0 or "index" evaluates down columns; 1 or "columns" evaluates across rows. Defaults to 0. |
skipna | bool; default True | Whether to omit missing values. Defaults to True. |
numeric_only | bool; default False | Whether to retain only float, integer, or Boolean data. |
Series — indexes of minima along the specified axis.
import pandas as pd
scores = pd.DataFrame(
{"alice": [8, 3, 6], "bob": [5, 7, 2]},
index=["round_1", "round_2", "round_3"],
)
print(scores.idxmin())
print(scores.idxmin(axis="columns"))The first call finds the row label containing each column's minimum; the second finds the column label containing each row's minimum.
Identify the row label associated with the lowest measurement in every column.
Determine which feature or category has the lowest value for each record.
Avoid non-numeric fields when reducing a mixed-type DataFrame.
It returns a Series containing the index label of the first minimum along the selected axis, rather than the minimum value itself. The default axis is 0, so each column produces one result.
Follow-up: How would you get the minimum value after finding its label? Use DataFrame.min with the same axis, or use the returned labels to select the corresponding entries.
Use axis="columns" (axis=1) to evaluate across each row and return the column label where that row's first minimum occurs. The default axis=0 evaluates down each column.
Follow-up: What happens when a row contains ties? The first minimum encountered in the column order is returned, because the method returns the first occurrence.
skipna defaults to True, so NA/null values are ignored. Setting skipna=False makes an NA cause ValueError, and an entirely missing DataFrame also raises ValueError.
Follow-up: How can the operation focus only on numeric data? Pass numeric_only=True, which includes floating-point, integer, and Boolean data.
DataFrame.minnumpy.ndarray.argmin