Skip to content

Commit e735fbb

Browse files
committed
DOC: modify examples and return in docs
1 parent a14a8be commit e735fbb

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

pandas/core/groupby/generic.py

Lines changed: 23 additions & 16 deletions
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
------
@@ -2508,8 +2508,8 @@ def idxmax(
25082508
25092509
Returns
25102510
-------
2511-
Series
2512-
Indexes of maxima in each group.
2511+
DataFrame
2512+
Indexes of maxima in each column according to the group.
25132513
25142514
Raises
25152515
------
@@ -2519,6 +2519,7 @@ def idxmax(
25192519
See Also
25202520
--------
25212521
Series.idxmax : Return index of the maximum element.
2522+
DataFrame.idxmax : Indexes of maxima along the specified axis.
25222523
25232524
Notes
25242525
-----
@@ -2532,6 +2533,7 @@ def idxmax(
25322533
... {
25332534
... "consumption": [10.51, 103.11, 55.48],
25342535
... "co2_emissions": [37.2, 19.66, 1712],
2536+
... "food_type": ["meat", "plant", "meat"]
25352537
... },
25362538
... index=["Pork", "Wheat Products", "Beef"],
25372539
... )
@@ -2542,12 +2544,14 @@ def idxmax(
25422544
Wheat Products 103.11 19.66
25432545
Beef 55.48 1712.00
25442546
2545-
By default, it returns the index for the maximum value in each column.
2547+
By default, it returns the index for the maximum value in each column according to the group.
2548+
2549+
>>> df.groupby("food_type").idxmax()
2550+
consumption co2_emissions
2551+
animal_type
2552+
animal Beef Beef
2553+
plant Wheat Products Wheat Products
25462554
2547-
>>> df.idxmax()
2548-
consumption Wheat Products
2549-
co2_emissions Beef
2550-
dtype: object
25512555
"""
25522556
return self._idxmax_idxmin("idxmax", numeric_only=numeric_only, skipna=skipna)
25532557

@@ -2570,8 +2574,8 @@ def idxmin(
25702574
25712575
Returns
25722576
-------
2573-
Series
2574-
Indexes of minima in each group.
2577+
DataFrame
2578+
Indexes of minima in each column according to the group.
25752579
25762580
Raises
25772581
------
@@ -2581,6 +2585,7 @@ def idxmin(
25812585
See Also
25822586
--------
25832587
Series.idxmin : Return index of the minimum element.
2588+
DataFrame.idxmin : Indexes of minima along the specified axis.
25842589
25852590
Notes
25862591
-----
@@ -2594,6 +2599,7 @@ def idxmin(
25942599
... {
25952600
... "consumption": [10.51, 103.11, 55.48],
25962601
... "co2_emissions": [37.2, 19.66, 1712],
2602+
... "food_type": ["meat", "plant", "meat"]
25972603
... },
25982604
... index=["Pork", "Wheat Products", "Beef"],
25992605
... )
@@ -2607,9 +2613,10 @@ def idxmin(
26072613
By default, it returns the index for the minimum value in each column.
26082614
26092615
>>> df.idxmin()
2610-
consumption Pork
2611-
co2_emissions Wheat Products
2612-
dtype: object
2616+
consumption co2_emissions
2617+
animal_type
2618+
animal Pork Pork
2619+
plant Wheat Products Wheat Products
26132620
"""
26142621
return self._idxmax_idxmin("idxmin", numeric_only=numeric_only, skipna=skipna)
26152622

0 commit comments

Comments
 (0)