Skip to main content
`Ctrl`+`K`

# pandas.api.typing.DataFrameGroupBy.idxmin

DataFrameGroupBy.idxmin(skipna=True, numeric_only=False)

  Return index of first occurrence of minimum in each group.

  Parameters:
    skipna bool, default True

      Exclude NA values.

    numeric_only bool, default False

      Include only float, int or boolean data.

  Returns:
    DataFrame

      Indexes of minima in each column according to the 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

  `Series.idxmin`

    Return index of the minimum element.

  `DataFrame.idxmin`

    Indexes of minima along the specified axis.

  Notes

  This method is the DataFrame version of `ndarray.argmin`.

  Examples

  Consider a dataset containing food consumption in Argentina.

      >>> df = pd.DataFrame(
      ...     {
      ...         "consumption": [10.51, 103.11, 55.48],
      ...         "co2_emissions": [37.2, 19.66, 1712],
      ...         "food_type": ["meat", "plant", "meat"],
      ...     },
      ...     index=["Pork", "Wheat Products", "Beef"],
      ... )

      >>> df
                      consumption  co2_emissions food_type
      Pork                  10.51         37.20       meat
      Wheat Products       103.11         19.66      plant
      Beef                  55.48       1712.00       meat

  By default, it returns the index for the minimum value in each column according to the group.

      >>> df.groupby("food_type").idxmin()
                    consumption   co2_emissions
      food_type
      meat                 Pork            Pork
      plant      Wheat Products  Wheat Products