-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Add doc for counting categorical dtype #59327
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
+28
−0
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4be568
Add doc for counting categorical dtype
jahn96 1348bdc
Move example to docstring instead
jahn96 d40849b
Remove backslash
jahn96 bc2378c
add line
jahn96 8497da5
Merge branch 'main' into categorical
jahn96 d838181
Undo the change in categorical.rst
jahn96 86facac
Rename it to Categorical Dtypes
jahn96 a847c13
undo categorical.rst
jahn96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1049,6 +1049,34 @@ def value_counts( | |||||
4.0 1 | ||||||
NaN 1 | ||||||
Name: count, dtype: int64 | ||||||
|
||||||
**categorial_dtypes** | ||||||
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.
Suggested change
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. Addressed here |
||||||
|
||||||
Rows with categorical type will be counted as one group | ||||||
if they have same categories and order. | ||||||
In the example below, even though ``a``, ``c``, and ``d`` | ||||||
all have the same data types of ``category``, | ||||||
only ``c`` and ``d`` will be counted as one group | ||||||
since ``a`` doesn't have the same categories. | ||||||
|
||||||
>>> df = pd.DataFrame({"a": [1], "b": ["2"], "c": [3], "d": [3]}) | ||||||
>>> df = df.astype({"a": "category", "c": "category", "d": "category"}) | ||||||
>>> df | ||||||
a b c d | ||||||
0 1 2 3 3 | ||||||
|
||||||
>>> df.dtypes | ||||||
a category | ||||||
b object | ||||||
c category | ||||||
d category | ||||||
dtype: object | ||||||
|
||||||
>>> df.dtypes.value_counts() | ||||||
category 2 | ||||||
category 1 | ||||||
object 1 | ||||||
Name: count, dtype: int64 | ||||||
""" | ||||||
return algorithms.value_counts_internal( | ||||||
self, | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you undo the changes in this file?
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.
Addressed here
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.
Looks like there's still changes in this file
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.
Ah sorry! Addressed here