-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add dropna=False to crosstab example #21413
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
Conversation
Hello @testvinder! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on June 11, 2018 at 09:29 Hours UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to the comments.
@gfyoung , are the suggestions viable?
pandas/core/reshape/pivot.py
Outdated
@@ -429,8 +429,9 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, | |||
|
|||
>>> foo = pd.Categorical(['a', 'b'], categories=['a', 'b', 'c']) | |||
>>> bar = pd.Categorical(['d', 'e'], categories=['d', 'e', 'f']) | |||
>>> crosstab(foo, bar) # 'c' and 'f' are not represented in the data, | |||
... # but they still will be counted in the output | |||
>>> crosstab(foo, bar, dropna=False) # 'c' and 'f' are not represented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@testvinder , just a suggestion, you could've actually just changed the output regarding the given code and mentioned in comments about the default value of dropna
being set to True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually just add an example instead of modifying this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 I actually think it's better to set ´dropnato
False`. The whole point of specifying the extra categories is to include them in the crosstab. It's a small change but the original is very confusing because the output cannot be reproduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@testvinder : Ah, yes, your point is well-taken. Can you update the original example with the correct output and add your example with dropna=False
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfyoung Sure, will do.
Codecov Report
@@ Coverage Diff @@
## master #21413 +/- ##
==========================================
- Coverage 91.89% 91.89% -0.01%
==========================================
Files 153 153
Lines 49596 49596
==========================================
- Hits 45576 45574 -2
- Misses 4020 4022 +2
Continue to review full report at Codecov.
|
I completely misread this PR and thought this was a larger change than it actually was. Sorry! |
@gfyoung yes, it's really just a tiny change that makes the documentation more clear. |
@testvinder : I just realized: your PR should be against the |
@gfyoung Done:-) Sorry for the mistake. This is all new to me. |
@testvinder : I re-applied your commits against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the base fixed, LGTM!
cc @jreback
thanks @testvinder |
@jreback just a small note, can you make sure the final commits gets a reasonable message? (normally you should see it in the github merge box), because now it is "Reapply all patches by @testvinder against master" :-) |
normally i remove all comments - guess missed that one |
Yeah, it's not about the comments (those go into the commit message body) but the title. But it's a bit strange github did it this wrongly, because normally the title is fine (probably because the commit was rebased and squashed) |
The above example code does not produce the output shown because dropna=True is default. Changing crosstab(foo, bar) to crosstab(foo, bar, dropna=False) fixes that and produces the shown output (which is also the expected and correct output).
git diff upstream/master -u -- "*.py" | flake8 --diff