Skip to content

DOC: update the pandas.Series.str.strip docstring #20628

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
42 changes: 40 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2094,8 +2094,46 @@ 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 whitespaces from string in Series.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily whitespaces.


Strip whitespace (including newlines) or given string from
each string in the Series/Index from %(side)s. Equivalent to
:meth:`str.%(method)s`.

Parameters
----------
to_strip : str or unicode
String or unicode to strip in the given string.

Examples
--------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples section goes after Returns

>>> # strip method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write sentences explaining what you're doing without making then Python comments. Check the docstring guide or other docstrings already improved.

>>> s = pd.Series([' This is a Test 1 '])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create a single Series with all the values you want to use in the examples, and then apply all operations to it.

>>> s
0 This is a Test 1
dtype: object
>>> s = s.str.strip()
>>> s
0 This is a Test 1
dtype: object
>>> # lstrip method
>>> s1 = pd.Series(['This is another Test'])
>>> s1
0 This is another Test
dtype: object
>>> s1 = s1.str.lstrip('This')
>>> s1
0 is another Test
dtype: object
>>> # rstrip method
>>> s2 = pd.Series(['This is the last test'])
>>> s2
0 This is the last test
dtype: object
>>> s2 = s2.str.rstrip('test')
>>> s2
0 This is the last
dtype: object

Returns
-------
Expand Down