Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.idxmin

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.

How it works

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.

Syntax

DataFrame.idxmin(axis=0, skipna=True, numeric_only=False)

Parameters

NameTypeDescription
axis0 or “index”, 1 or “columns”; default 0Axis to reduce: 0 or "index" evaluates down columns; 1 or "columns" evaluates across rows. Defaults to 0.
skipnabool; default TrueWhether to omit missing values. Defaults to True.
numeric_onlybool; default FalseWhether to retain only float, integer, or Boolean data.

Returns

Series — indexes of minima along the specified axis.

Key points

  • The result identifies the label at the first occurrence of the smallest value along the chosen axis.
  • Missing values do not participate when skipna remains at its default True.
  • axis=0 or "index" computes one result per column, while axis=1 or "columns" computes one per row.
  • The return type is a Series whose values are labels of minima along the selected direction.
  • Without an axis argument, each DataFrame column contributes its minimum's row index.
  • Pass axis="columns" when each row should yield the column label associated with its minimum.

Common mistakes

  • An all-missing DataFrame, or any missing value when skipna=False, raises ValueError.
  • With numeric_only=True, non-numeric columns are excluded from the calculation.

Example: Find locations of minima

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.

When to use it

Column-wise minima

Identify the row label associated with the lowest measurement in every column.

Row-wise minima

Determine which feature or category has the lowest value for each record.

Numeric-only reduction

Avoid non-numeric fields when reducing a mixed-type DataFrame.

Interview questions

QWhat does DataFrame.idxmin return by default?

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.

QHow do you find the minimum-containing column for every row?

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.

QHow are missing values handled?

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.min
  • numpy.ndarray.argmin

Source: pandas.DataFrame.idxmin — pandas 2.3.3 documentation. Checked 2026-10-15.