-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: update the pandas.Series.str.strip docstring #20863
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 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a54a326
DOC: update the pandas.Series.str.strip docstring
Cheukting fee3c61
DOC: update the pandas.Series.str.strip docstring
Cheukting 8b36512
typo fixing and improve Index example
Cheukting 660b4fc
Fix PEP8
Cheukting e6fe921
Improve parameter explaination
Cheukting fd3eda2
Improve documentation, adding lstrip and rstrip example
Cheukting c69b1e3
simplify lstrip and rstrip
Cheukting 5160feb
added np.nan example
Cheukting 0d6a4cc
Merge remote-tracking branch 'upstream/master' into Doc_str_strip
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 |
---|---|---|
|
@@ -2151,12 +2151,60 @@ def encode(self, encoding, errors="strict"): | |
return self._wrap_result(result) | ||
|
||
_shared_docs['str_strip'] = (""" | ||
Strip whitespace (including newlines) from each string in the | ||
Series/Index from %(side)s. Equivalent to :meth:`str.%(method)s`. | ||
Remove leading and trailing characters. | ||
|
||
Strip whitespaces (including newlines) or a set of specified characters | ||
from each string in the Series/Index from %(side)s. | ||
Equivalent to :meth:`str.%(method)s`. | ||
|
||
Parameters | ||
---------- | ||
to_strip : str or None, default None (whitespaces are removed) | ||
Specifying the set of characters to be removed. | ||
All combinations of this set of characters will be stripped. | ||
|
||
Returns | ||
------- | ||
stripped : Series/Index of objects | ||
Series/Index of objects | ||
|
||
See Also | ||
-------- | ||
Series.str.strip : Remove leading and trailing characters in Series/Index | ||
Series.str.lstrip : Remove leading characters in Series/Index | ||
Series.str.rstrip : Remove trailing characters in Series/Index | ||
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(['1. Ant. ', '2. Bee!\n', '3. Cat?\t']) | ||
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. can you add a np.nan in the example (in place of an entry or in addition is ok) |
||
>>> s | ||
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. This is simple enough that you don't need to print the Series as is |
||
0 1. Ant. | ||
1 2. Bee!\n | ||
2 3. Cat?\t | ||
dtype: object | ||
|
||
>>> s.str.strip() | ||
0 1. Ant. | ||
1 2. Bee! | ||
2 3. Cat? | ||
dtype: object | ||
|
||
>>> s.str.lstrip('123.') | ||
0 Ant. | ||
1 Bee!\n | ||
2 Cat?\t | ||
dtype: object | ||
|
||
>>> s.str.rstrip('.!? \n\t') | ||
0 1. Ant | ||
1 2. Bee | ||
2 3. Cat | ||
dtype: object | ||
|
||
>>> s.str.strip('123.!? \n\t') | ||
0 Ant | ||
1 Bee | ||
2 Cat | ||
dtype: object | ||
""") | ||
|
||
@Appender(_shared_docs['str_strip'] % dict(side='left and right sides', | ||
|
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.
the coment about whitespaces are removed should be on the next line with a case, e.g.
If None then whitespaces are removed