Skip to main content
`Ctrl`+`K`

# pandas.api.typing.SeriesGroupBy.idxmax

SeriesGroupBy.idxmax(skipna=True)

  Return the row label of the maximum value.

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

  Parameters:
    skipna bool, default True

      Exclude NA values.

  Returns:
    Series

      Indexes of maxima 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.argmax`

    Return indices of the maximum values along the given axis.

  `DataFrame.idxmax`

    Return index of first occurrence of maximum over requested axis.

  `Series.idxmin`

    Return index label of the first occurrence of minimum 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"]).idxmax()
      a   2023-01-15
      b   2023-02-15
      dtype: datetime64[us]