8000 DOC: Added note about groupby excluding Decimal columns by default by pdpark · Pull Request #18953 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DOC: Added note about groupby excluding Decimal columns by default #18953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added note about groupby excluding Decimal columns by default
  • Loading branch information
Patrick Park committed Oct 11, 2018
commit df32828a3f29e627f9d9c3ac25162df9dbdbdb05
25 changes: 25 additions & 0 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,31 @@ Note that ``df.groupby('A').colname.std().`` is more efficient than
is only interesting over one column (here ``colname``), it may be filtered
*before* applying the aggregation function.

.. note::
Decimal and object columns are also "nuisance" columns. They are excluded from aggregate functions automatically in groupby.

If you do wish to include decimal or object columns in an aggregation with other non-nuisance data types, you must do so explicitly.

.. ipython:: python

from decimal import Decimal
dec = pd.DataFrame(
{'id': [123, 456, 123, 456],
'int_column': [1, 2, 3, 4],
'dec_column1': [Decimal('0.50'), Decimal('0.15'), Decimal('0.25'), Decimal('0.40')]
},
columns=['id','int_column','dec_column']
)

# Decimal columns can be sum'd explicitly by themselves...
dec.groupby(['id'], as_index=False)['dec_column'].sum()

# ...but cannot be combined with standard data types or they will be excluded
dec.groupby(['id'], as_index=False)['int_column','dec_column'].sum()

# Use .agg function to aggregate over standard and "nuisance" data types at the same time
dec.groupby(['id'], as_index=False).agg({'int_column': 'sum', 'dec_column': 'sum'})

.. _groupby.missing:

NA and NaT group handling
Expand Down
0