-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Implement DataFrame.value_counts #27350
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 1 commit
3d81526
699ac42
2e06d15
9e725c7
6437cfc
078d421
619f86c
ab897a9
ef8d565
362641a
181b577
3740bc2
19a6a06
c927f4a
11521c0
8539556
af3c6f3
e1f17ac
999ca18
cd7a8b6
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 |
---|---|---|
|
@@ -8387,6 +8387,48 @@ def isin(self, values): | |
self.columns, | ||
) | ||
|
||
def value_counts(self): | ||
""" | ||
The number of times each unique row appears in the DataFrame. | ||
|
||
Returns | ||
------- | ||
counts : Series | ||
|
||
See Also | ||
-------- | ||
Series.value_counts: Equivalent method on Series. | ||
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. we have more options on the Series.value_counts, dropna for example these need to be implemented 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. There's no option in group_by to not drop rows containing a NaN. How do I go about implementing that case? 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. I would be OK with raising a NotImplementedError for that case 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. Added. This changed the method pretty significantly. PTAL. 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. The single-column case now works, but the code raises |
||
|
||
Examples | ||
-------- | ||
|
||
>>> df = pd.DataFrame({'num_legs': [2, 4, 4], 'num_wings': [2, 0, 0]}, | ||
... index=['falcon', 'dog', 'cat']) | ||
>>> df | ||
num_legs num_wings | ||
falcon 2 2 | ||
dog 4 0 | ||
cat 4 0 | ||
|
||
>>> df.value_counts() | ||
(4, 0) 2 | ||
Strilanc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(2, 2) 1 | ||
dtype: int64 | ||
|
||
>>> df1col = df[['num_legs']] | ||
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. the 2nd example is showing how this works for a Series? 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.
|
||
>>> df1col | ||
num_legs | ||
falcon 2 | ||
dog 4 | ||
cat 4 | ||
|
||
>>> df1col.value_counts() | ||
(4,) 2 | ||
(2,) 1 | ||
dtype: int64 | ||
""" | ||
return self.apply(tuple, 1).value_counts() | ||
Strilanc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Add plotting methods to DataFrame | ||
plot = CachedAccessor("plot", pandas.plotting.PlotAccessor) | ||
|
Uh oh!
There was an error while loading. Please reload this page.