Skip to content

Commit d56b584

Browse files
pdparkgfyoung
pdpark
authored andcommitted
Added note about groupby excluding Decimal columns by default
1 parent 45e55af commit d56b584

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
@@ -525,6 +525,28 @@ a trivial example is ``df.groupby('A').agg(lambda ser: 1)``. Note that
525525
:meth:`~pd.core.groupby.DataFrameGroupBy.nth` can act as a reducer *or* a
526526
filter, see :ref:`here <groupby.nth>`.
527527

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+
528550
.. _groupby.aggregate.multifunc:
529551

530552
Applying multiple functions at once

0 commit comments

Comments
 (0)