Skip to content
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

BUG: Crosstab margins ignoring dropna #12614

Closed
wants to merge 6 commits into from
Closed
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
Modified _generate_marginal_results
To fix bug #12577: Crosstab margins ignoring dropna
  • Loading branch information
OXPHOS committed Mar 14, 2016
commit 9c0d99bcf5e0ac7a0fbea513c2127f62cda691af
6 changes: 3 additions & 3 deletions pandas/tools/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _all_key(key):
return (key, margins_name) + ('',) * (len(cols) - 1)

if len(rows) > 0:
margin = data[rows + values].groupby(rows).agg(aggfunc)
margin = data[data[cols].notnull().any(axis=1)][rows + values].groupby(rows).agg(aggfunc)
cat_axis = 1

for key, piece in table.groupby(level=0, axis=cat_axis):
Expand Down Expand Up @@ -304,7 +304,7 @@ def _all_key(key):
margin_keys = table.columns

if len(cols) > 0:
row_margin = data[cols + values].groupby(cols).agg(aggfunc)
row_margin = data[data[rows].notnull().any(axis=1)][cols + values].groupby(cols).agg(aggfunc)
row_margin = row_margin.stack()

# slight hack
Expand Down Expand Up @@ -462,4 +462,4 @@ def _get_names(arrs, names, prefix='row'):
if not isinstance(names, list):
names = list(names)

return names
return names