-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Update the pandas.Series.str.count() docstring (Delhi) #20154
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
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,15 +202,43 @@ def str_count(arr, pat, flags=0): | |
""" | ||
Count occurrences of pattern in each string of the Series/Index. | ||
|
||
This function is used to count the number of times a particular regex | ||
pattern is repeated in each of the string elements of the | ||
:class:`~pandas.Series`. | ||
|
||
Parameters | ||
---------- | ||
pat : string, valid regular expression | ||
flags : int, default 0 (no flags) | ||
re module flags, e.g. re.IGNORECASE | ||
pat : str | ||
Valid regular expression. | ||
flags : int, default 0, meaning no flags | ||
Flags for re module, e.g. re.IGNORECASE. | ||
|
||
Returns | ||
------- | ||
counts : Series/Index of integer values | ||
|
||
Notes | ||
----- | ||
Some characters need to be escaped when passing in pat. | ||
eg. '$' has a special meaning in regex and must be escaped when finding | ||
specifically this char. | ||
|
||
Examples | ||
-------- | ||
Take a look at | ||
`this link <https://docs.python.org/3/howto/regex.html#compilation-flags>`_ | ||
for the list of all possible flags that can be used. | ||
|
||
>>> s = pd.Series(['A', 'B', 'Aaba', 'Baca', np.nan, 'CABA', 'cat']) | ||
>>> s.str.count('a') | ||
0 0.0 | ||
1 0.0 | ||
2 2.0 | ||
3 2.0 | ||
4 NaN | ||
5 0.0 | ||
6 1.0 | ||
dtype: float64 | ||
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. Add an examle with special characters like 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 I remove the note in the doc? |
||
""" | ||
regex = re.compile(pat, flags=flags) | ||
f = lambda x: len(regex.findall(x)) | ||
|
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.
Maybe move this link to be under the flags parameter?
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 like that idea, will do