@@ -1321,8 +1321,8 @@ def idxmin(self, skipna: bool = True) -> Series:
1321
1321
1322
1322
Returns
1323
1323
-------
1324
- Index
1325
- Label of the minimum value .
1324
+ Series
1325
+ Indexes of minima in each group .
1326
1326
1327
1327
Raises
1328
1328
------
@@ -1374,8 +1374,8 @@ def idxmax(self, skipna: bool = True) -> Series:
1374
1374
1375
1375
Returns
1376
1376
-------
1377
- Index
1378
- Label of the maximum value .
1377
+ Series
1378
+ Indexes of maxima in each group .
1379
1379
1380
1380
Raises
1381
1381
------
@@ -2508,8 +2508,8 @@ def idxmax(
2508
2508
2509
2509
Returns
2510
2510
-------
2511
- Series
2512
- Indexes of maxima in each group.
2511
+ DataFrame
2512
+ Indexes of maxima in each column according to the group.
2513
2513
2514
2514
Raises
2515
2515
------
@@ -2519,6 +2519,7 @@ def idxmax(
2519
2519
See Also
2520
2520
--------
2521
2521
Series.idxmax : Return index of the maximum element.
2522
+ DataFrame.idxmax : Indexes of maxima along the specified axis.
2522
2523
2523
2524
Notes
2524
2525
-----
@@ -2532,6 +2533,7 @@ def idxmax(
2532
2533
... {
2533
2534
... "consumption": [10.51, 103.11, 55.48],
2534
2535
... "co2_emissions": [37.2, 19.66, 1712],
2536
+ ... "food_type": ["meat", "plant", "meat"]
2535
2537
... },
2536
2538
... index=["Pork", "Wheat Products", "Beef"],
2537
2539
... )
@@ -2542,12 +2544,14 @@ def idxmax(
2542
2544
Wheat Products 103.11 19.66
2543
2545
Beef 55.48 1712.00
2544
2546
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
2546
2554
2547
- >>> df.idxmax()
2548
- consumption Wheat Products
2549
- co2_emissions Beef
2550
- dtype: object
2551
2555
"""
2552
2556
return self ._idxmax_idxmin ("idxmax" , numeric_only = numeric_only , skipna = skipna )
2553
2557
@@ -2570,8 +2574,8 @@ def idxmin(
2570
2574
2571
2575
Returns
2572
2576
-------
2573
- Series
2574
- Indexes of minima in each group.
2577
+ DataFrame
2578
+ Indexes of minima in each column according to the group.
2575
2579
2576
2580
Raises
2577
2581
------
@@ -2581,6 +2585,7 @@ def idxmin(
2581
2585
See Also
2582
2586
--------
2583
2587
Series.idxmin : Return index of the minimum element.
2588
+ DataFrame.idxmin : Indexes of minima along the specified axis.
2584
2589
2585
2590
Notes
2586
2591
-----
@@ -2594,6 +2599,7 @@ def idxmin(
2594
2599
... {
2595
2600
... "consumption": [10.51, 103.11, 55.48],
2596
2601
... "co2_emissions": [37.2, 19.66, 1712],
2602
+ ... "food_type": ["meat", "plant", "meat"]
2597
2603
... },
2598
2604
... index=["Pork", "Wheat Products", "Beef"],
2599
2605
... )
@@ -2607,9 +2613,10 @@ def idxmin(
2607
2613
By default, it returns the index for the minimum value in each column.
2608
2614
2609
2615
>>> 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
2613
2620
"""
2614
2621
return self ._idxmax_idxmin ("idxmin" , numeric_only = numeric_only , skipna = skipna )
2615
2622
0 commit comments