-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
FIX value_counts should skip NaT #7424
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,7 +245,7 @@ def min(self): | |
return pandas.core.nanops.nanmin(self.values) | ||
|
||
def value_counts(self, normalize=False, sort=True, ascending=False, | ||
bins=None): | ||
bins=None, dropna=True): | ||
""" | ||
Returns object containing counts of unique values. The resulting object | ||
will be in descending order so that the first element is the most | ||
|
@@ -263,14 +263,16 @@ def value_counts(self, normalize=False, sort=True, ascending=False, | |
bins : integer, optional | ||
Rather than count values, group them into half-open bins, | ||
a convenience for pd.cut, only works with numeric data | ||
dropna : boolean, default False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
Don't include counts of NaN | ||
|
||
Returns | ||
------- | ||
counts : Series | ||
""" | ||
from pandas.core.algorithms import value_counts | ||
return value_counts(self.values, sort=sort, ascending=ascending, | ||
normalize=normalize, bins=bins) | ||
normalize=normalize, bins=bins, dropna=dropna) | ||
|
||
def unique(self): | ||
""" | ||
|
@@ -284,15 +286,15 @@ def unique(self): | |
from pandas.core.nanops import unique1d | ||
return unique1d(self.values) | ||
|
||
def nunique(self): | ||
def nunique(self, dropna=True): | ||
""" | ||
Return count of unique elements in the object. Excludes NA values. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should add explanation of the new parameter (just as in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that looks right (should be |
||
Returns | ||
------- | ||
nunique : int | ||
""" | ||
return len(self.value_counts()) | ||
return len(self.value_counts(dropna=dropna)) | ||
|
||
def factorize(self, sort=False, na_sentinel=-1): | ||
""" | ||
|
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 think this should be
True
?