Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: DataFrameGroupBy.idxmin() returns DataFrame, documentation says Serie #60474

Merged
merged 9 commits into from
Dec 3, 2024
44 changes: 26 additions & 18 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ def idxmin(self, skipna: bool = True) -> Series:

Returns
-------
Index
Label of the minimum value.
Series
Indexes of minima in each group.

Raises
------
Expand Down Expand Up @@ -1374,8 +1374,8 @@ def idxmax(self, skipna: bool = True) -> Series:

Returns
-------
Index
Label of the maximum value.
Series
Indexes of maxima in each group.

Raises
------
Expand Down Expand Up @@ -2508,8 +2508,8 @@ def idxmax(

Returns
-------
Series
Indexes of maxima in each group.
DataFrame
Indexes of maxima in each column according to the group.

Raises
------
Expand All @@ -2519,6 +2519,7 @@ def idxmax(
See Also
--------
Series.idxmax : Return index of the maximum element.
DataFrame.idxmax : Indexes of maxima along the specified axis.

Notes
-----
Expand All @@ -2532,6 +2533,7 @@ def idxmax(
... {
... "consumption": [10.51, 103.11, 55.48],
... "co2_emissions": [37.2, 19.66, 1712],
... "food_type": ["meat", "plant", "meat"],
... },
... index=["Pork", "Wheat Products", "Beef"],
... )
Expand All @@ -2542,12 +2544,14 @@ def idxmax(
Wheat Products 103.11 19.66
Beef 55.48 1712.00

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

>>> df.idxmax()
consumption Wheat Products
co2_emissions Beef
dtype: object
>>> df.groupby("food_type").idxmax()
consumption co2_emissions
food_type
animal Beef Beef
plant Wheat Products Wheat Products
"""
return self._idxmax_idxmin("idxmax", numeric_only=numeric_only, skipna=skipna)

Expand All @@ -2570,8 +2574,8 @@ def idxmin(

Returns
-------
Series
Indexes of minima in each group.
DataFrame
Indexes of minima in each column according to the group.

Raises
------
Expand All @@ -2581,6 +2585,7 @@ def idxmin(
See Also
--------
Series.idxmin : Return index of the minimum element.
DataFrame.idxmin : Indexes of minima along the specified axis.

Notes
-----
Expand All @@ -2594,6 +2599,7 @@ def idxmin(
... {
... "consumption": [10.51, 103.11, 55.48],
... "co2_emissions": [37.2, 19.66, 1712],
... "food_type": ["meat", "plant", "meat"],
... },
... index=["Pork", "Wheat Products", "Beef"],
... )
Expand All @@ -2604,12 +2610,14 @@ def idxmin(
Wheat Products 103.11 19.66
Beef 55.48 1712.00

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

>>> df.idxmin()
consumption Pork
co2_emissions Wheat Products
dtype: object
>>> df.groupby("food_type").idxmin()
consumption co2_emissions
food_type
animal Pork Pork
plant Wheat Products Wheat Products
"""
return self._idxmax_idxmin("idxmin", numeric_only=numeric_only, skipna=skipna)

Expand Down
Loading