-
-
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
Changes from 5 commits
a54a326
fee3c61
8b36512
660b4fc
e6fe921
fd3eda2
c69b1e3
5160feb
0d6a4cc
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 |
---|---|---|
|
@@ -2151,12 +2151,54 @@ 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, optional | ||
Specifying the set of characters to be removed. | ||
All combinations of this set of characters will be stripped. | ||
Default value is None, which means whaitspaces will be removed. | ||
|
||
Returns | ||
------- | ||
stripped : Series/Index of objects | ||
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 get rid of the name |
||
|
||
See Also | ||
-------- | ||
str.slice : Slice substrings from each element in the Series/Index | ||
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.
Not sure if there is anything else related, but we should have here |
||
|
||
Examples | ||
-------- | ||
Stripping whitespaces for Series | ||
|
||
>>> s = pd.Series([' ant', 'bee ', ' cat ']) | ||
|
||
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 blank line is unnecessary. |
||
>>> 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 ant | ||
1 bee | ||
2 cat | ||
dtype: object | ||
|
||
>>> s.str.strip() | ||
0 ant | ||
1 bee | ||
2 cat | ||
dtype: object | ||
|
||
Stripping a set of characters for Index | ||
|
||
>>> idx = pd.Index(['1.ant ','2._bee__','3. cat_']) | ||
|
||
>>> idx | ||
Index(['1.ant ', '2._bee__', '3. cat_'], dtype='object') | ||
|
||
>>> idx.str.strip('123._ ') | ||
Index(['ant', 'bee', 'cat'], dtype='object') | ||
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 we use a single example, with a single
|
||
""") | ||
|
||
@Appender(_shared_docs['str_strip'] % dict(side='left and right sides', | ||
|
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.
this is not optional, the default is
Ǹone
which means whitespaces are stripped You can addto_strip : str or None, default None (whitespaces are removed)
. And take it out from the description.