Skip to content

Commit 155e85e

Browse files
author
pdpark
committed
Added note about groupby excluding Decimal columns by default
1 parent c1af9a8 commit 155e85e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/source/groupby.rst

+22
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,28 @@ index are the group names and whose values are the sizes of each group.
497497

498498
``nth`` can act as a reducer *or* a filter, see :ref:`here <groupby.nth>`
499499

500+
Decimal columns are "nuisance" columns that .agg automatically excludes in groupby.
501+
502+
If you do wish to aggregate them you must do so explicitly:
503+
504+
.. ipython:: python
505+
506+
from decimal import Decimal
507+
dec = pd.DataFrame(
508+
{'name': ['foo', 'bar', 'foo', 'bar'],
509+
'title': ['boo', 'far', 'boo', 'far'],
510+
'id': [123, 456, 123, 456],
511+
'int_column': [1, 2, 3, 4],
512+
'dec_column1': [Decimal('0.50'), Decimal('0.15'), Decimal('0.25'), Decimal('0.40')],
513+
'dec_column2': [Decimal('0.20'), Decimal('0.30'), Decimal('0.55'), Decimal('0.60')]
514+
},
515+
columns=['name','title','id','int_column','dec_column1','dec_column2']
516+
)
517+
518+
dec.groupby(['name', 'title', 'id'], as_index=False).sum()
519+
520+
dec.groupby(['name', 'title', 'id'], as_index=False).agg({'dec_column1': 'sum', 'dec_column2': 'sum'})
521+
500522
.. _groupby.aggregate.multifunc:
501523

502524
Applying multiple functions at once

0 commit comments

Comments
 (0)