@@ -668,8 +668,9 @@ column, which produces an aggregated result with a hierarchical column index:
668
668
grouped[[" C" , " D" ]].agg([" sum" , " mean" , " std" ])
669
669
670
670
671
- The resulting aggregations are named after the functions themselves. If you
672
- need to rename, then you can add in a chained operation for a ``Series `` like this:
671
+ The resulting aggregations are named after the functions themselves.
672
+
673
+ For a ``Series ``, if you need to rename, you can add in a chained operation like this:
673
674
674
675
.. ipython :: python
675
676
@@ -679,8 +680,19 @@ need to rename, then you can add in a chained operation for a ``Series`` like th
679
680
.rename(columns = {" sum" : " foo" , " mean" : " bar" , " std" : " baz" })
680
681
)
681
682
683
+ Or, you can simply pass a list of tuples each with the name of the new column and the aggregate function:
684
+
685
+ .. ipython :: python
686
+
687
+ (
688
+ grouped[" C" ]
689
+ .agg([(" foo" , " sum" ), (" bar" , " mean" ), (" baz" , " std" )])
690
+ )
691
+
682
692
For a grouped ``DataFrame ``, you can rename in a similar manner:
683
693
694
+ By chaining ``rename `` operation,
695
+
684
696
.. ipython :: python
685
697
686
698
(
@@ -689,6 +701,16 @@ For a grouped ``DataFrame``, you can rename in a similar manner:
689
701
)
690
702
)
691
703
704
+ Or, passing a list of tuples,
705
+
706
+ .. ipython :: python
707
+
708
+ (
709
+ grouped[[" C" , " D" ]].agg(
710
+ [(" foo" , " sum" ), (" bar" , " mean" ), (" baz" , " std" )]
711
+ )
712
+ )
713
+
692
714
.. note ::
693
715
694
716
In general, the output column names should be unique, but pandas will allow
0 commit comments