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