@@ -525,6 +525,28 @@ a trivial example is ``df.groupby('A').agg(lambda ser: 1)``. Note that
525
525
:meth: `~pd.core.groupby.DataFrameGroupBy.nth ` can act as a reducer *or * a
526
526
filter, see :ref: `here <groupby.nth >`.
527
527
528
+ Decimal columns are "nuisance" columns that .agg automatically excludes in groupby.
529
+
530
+ If you do wish to aggregate them you must do so explicitly:
531
+
532
+ .. ipython :: python
533
+
534
+ from decimal import Decimal
535
+ dec = pd.DataFrame(
536
+ {' name' : [' foo' , ' bar' , ' foo' , ' bar' ],
537
+ ' title' : [' boo' , ' far' , ' boo' , ' far' ],
538
+ ' id' : [123 , 456 , 123 , 456 ],
539
+ ' int_column' : [1 , 2 , 3 , 4 ],
540
+ ' dec_column1' : [Decimal(' 0.50' ), Decimal(' 0.15' ), Decimal(' 0.25' ), Decimal(' 0.40' )],
541
+ ' dec_column2' : [Decimal(' 0.20' ), Decimal(' 0.30' ), Decimal(' 0.55' ), Decimal(' 0.60' )]
542
+ },
543
+ columns = [' name' ,' title' ,' id' ,' int_column' ,' dec_column1' ,' dec_column2' ]
544
+ )
545
+
546
+ dec.groupby([' name' , ' title' , ' id' ], as_index = False ).sum()
547
+
548
+ dec.groupby([' name' , ' title' , ' id' ], as_index = False ).agg({' dec_column1' : ' sum' , ' dec_column2' : ' sum' })
549
+
528
550
.. _groupby.aggregate.multifunc :
529
551
530
552
Applying multiple functions at once
0 commit comments