Skip to content

Commit 844b319

Browse files
authored
DOC: DataFrameGroupBy.idxmin() returns DataFrame, documentation says Serie (pandas-dev#60474)
* DOC: modify examples and return in docs * DOC: fix examples * DOC: unify * Whitespace * Pre commit * Double line breaks * DOC: finally rann pre commit * Remove unused notebook
1 parent 0c09383 commit 844b319

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

pandas/core/groupby/generic.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,8 @@ def idxmin(self, skipna: bool = True) -> Series:
13211321
13221322
Returns
13231323
-------
1324-
Index
1325-
Label of the minimum value.
1324+
Series
1325+
Indexes of minima in each group.
13261326
13271327
Raises
13281328
------
@@ -1374,8 +1374,8 @@ def idxmax(self, skipna: bool = True) -> Series:
13741374
13751375
Returns
13761376
-------
1377-
Index
1378-
Label of the maximum value.
1377+
Series
1378+
Indexes of maxima in each group.
13791379
13801380
Raises
13811381
------
@@ -2512,8 +2512,8 @@ def idxmax(
25122512
25132513
Returns
25142514
-------
2515-
Series
2516-
Indexes of maxima in each group.
2515+
DataFrame
2516+
Indexes of maxima in each column according to the group.
25172517
25182518
Raises
25192519
------
@@ -2523,6 +2523,7 @@ def idxmax(
25232523
See Also
25242524
--------
25252525
Series.idxmax : Return index of the maximum element.
2526+
DataFrame.idxmax : Indexes of maxima along the specified axis.
25262527
25272528
Notes
25282529
-----
@@ -2536,6 +2537,7 @@ def idxmax(
25362537
... {
25372538
... "consumption": [10.51, 103.11, 55.48],
25382539
... "co2_emissions": [37.2, 19.66, 1712],
2540+
... "food_type": ["meat", "plant", "meat"],
25392541
... },
25402542
... index=["Pork", "Wheat Products", "Beef"],
25412543
... )
@@ -2546,12 +2548,14 @@ def idxmax(
25462548
Wheat Products 103.11 19.66
25472549
Beef 55.48 1712.00
25482550
2549-
By default, it returns the index for the maximum value in each column.
2551+
By default, it returns the index for the maximum value in each column
2552+
according to the group.
25502553
2551-
>>> df.idxmax()
2552-
consumption Wheat Products
2553-
co2_emissions Beef
2554-
dtype: object
2554+
>>> df.groupby("food_type").idxmax()
2555+
consumption co2_emissions
2556+
food_type
2557+
animal Beef Beef
2558+
plant Wheat Products Wheat Products
25552559
"""
25562560
return self._idxmax_idxmin("idxmax", numeric_only=numeric_only, skipna=skipna)
25572561

@@ -2574,8 +2578,8 @@ def idxmin(
25742578
25752579
Returns
25762580
-------
2577-
Series
2578-
Indexes of minima in each group.
2581+
DataFrame
2582+
Indexes of minima in each column according to the group.
25792583
25802584
Raises
25812585
------
@@ -2585,6 +2589,7 @@ def idxmin(
25852589
See Also
25862590
--------
25872591
Series.idxmin : Return index of the minimum element.
2592+
DataFrame.idxmin : Indexes of minima along the specified axis.
25882593
25892594
Notes
25902595
-----
@@ -2598,6 +2603,7 @@ def idxmin(
25982603
... {
25992604
... "consumption": [10.51, 103.11, 55.48],
26002605
... "co2_emissions": [37.2, 19.66, 1712],
2606+
... "food_type": ["meat", "plant", "meat"],
26012607
... },
26022608
... index=["Pork", "Wheat Products", "Beef"],
26032609
... )
@@ -2608,12 +2614,14 @@ def idxmin(
26082614
Wheat Products 103.11 19.66
26092615
Beef 55.48 1712.00
26102616
2611-
By default, it returns the index for the minimum value in each column.
2617+
By default, it returns the index for the minimum value in each column
2618+
according to the group.
26122619
2613-
>>> df.idxmin()
2614-
consumption Pork
2615-
co2_emissions Wheat Products
2616-
dtype: object
2620+
>>> df.groupby("food_type").idxmin()
2621+
consumption co2_emissions
2622+
food_type
2623+
animal Pork Pork
2624+
plant Wheat Products Wheat Products
26172625
"""
26182626
return self._idxmax_idxmin("idxmin", numeric_only=numeric_only, skipna=skipna)
26192627

0 commit comments

Comments
 (0)