pandas.core.groupby.SeriesGroupBy.idxmin#

SeriesGroupBy.idxmin(skipna=True)[source]#

Return the row label of the minimum value.

If multiple values equal the minimum, the first row label with that value is returned.

Parameters:
skipnabool, default True

Exclude NA values.

Returns:
Index

Label of the minimum value.

Raises:
ValueError

If the Series is empty or skipna=False and any value is NA.

See also

numpy.argmin

Return indices of the minimum values along the given axis.

DataFrame.idxmin

Return index of first occurrence of minimum over requested axis.

Series.idxmax

Return index label of the first occurrence of maximum of values.

Examples

>>> ser = pd.Series(
...     [1, 2, 3, 4],
...     index=pd.DatetimeIndex(
...         ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
...     ),
... )
>>> ser
2023-01-01    1
2023-01-15    2
2023-02-01    3
2023-02-15    4
dtype: int64
>>> ser.groupby(["a", "a", "b", "b"]).idxmin()
a   2023-01-01
b   2023-02-01
dtype: datetime64[s]