Skip to content

DOC: improve the shared docstring of Series.str.strip() #20897

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2151,12 +2151,49 @@ 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`.
Strip combinations of characters from the %(side)s of strings.

Operates on each element in the given String/Index, and is equivalent to
:meth:`str.%(method)s`.

Parameters
----------
to_strip : str or unicode, optional
String or unicode specifying the set of characters to be removed from
the %(side)s. If omitted or None, the strip method defaults to removing
whitespace and newlines.

Returns
-------
stripped : Series/Index of objects

See Also
--------
Series.str.strip : Removes defined characters from both sides
Series.str.lstrip : Removes defined characters from the left side
Series.str.rstrip : Removes defined characters from the right side

Examples
--------
>>> s = pd.Series(data=[' spacious ', '__-left_foo',
... '-__center_foo__-', 'right_foo-__'])
>>> s.str.strip()[0]
'spacious'

Rather than string matching, all combinations of the `to_strip` parameter's
characters are removed.

>>> s.str.lstrip("-_")[1:]
1 left_foo
2 center_foo__-
3 right_foo-__
dtype: object

>>> s.str.rstrip("-_")[1:]
1 __-left_foo
2 -__center_foo
3 right_foo
dtype: object
""")

@Appender(_shared_docs['str_strip'] % dict(side='left and right sides',
Expand Down