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:
Series

Indexes of minima in each group.

Raises:
ValueError

When there are no valid values for a group. Then can happen if:

  • There is an unobserved group and observed=False.

  • All values for a group are NA.

  • Some values for a group are NA and skipna=False.

Changed in version 3.0.0: Previously if all values for a group are NA or some values for a group are NA and skipna=False, this method would return NA. Now it raises instead.

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]
On this page

This Page