liveBook · Manning

Pandas Series.idxmin

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

idxmin is a pandas operation that returns the index label associated with the minimum value.

Think of a Series as a list of measurements with labels attached. idxmin() returns the index label belonging to its smallest value, letting you locate the minimum without manually comparing rows. section 1.15

Locate a minimum value

For a Series s, s.idxmin() gives the index of one minimum element. If several elements share the minimum, idxmin() returns only one location. To find every tied location, build a boolean mask with s == s.min(), then use s.loc[s == s.min()]. section 1.15

Return a date instead of a row number

When dates form a DataFrame index, df.set_index('date').idxmin() returns the date associated with the minimum value column. The matching idxmax() call finds the date of the maximum; agg(['idxmin', 'idxmax']) obtains both in one operation. section 3.17

Use the result with these distinctions in mind:

  • Use idxmin() when one minimum location is sufficient. section 1.15
  • Use boolean masking when every tied minimum must be selected or modified. section 1.15

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains the returned label and the single-location behavior, while deferring implementation internals.
Examples
Uses a random numeric Series and a date-indexed market-price DataFrame to demonstrate minima, ties, and paired extrema.
What it assumes
Assumes familiarity with pandas Series, DataFrame indexes, loc selection, and boolean masks.
What you can do after
Apply it via pandas to retrieve a minimum's label and switch to masking when all tied minima matter.
How it connects
Connects minimum selection with indexes, boolean masking, idxmax, and aggregation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.