Skip to content
Merged
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
13 changes: 12 additions & 1 deletion pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,7 @@ def encode(self, encoding, errors="strict"):

Strip whitespaces (including newlines) or a set of specified characters
from each string in the Series/Index from %(side)s.
Replaces any non-strings in Series with NaNs.
Equivalent to :meth:`str.%(method)s`.

Parameters
Expand All @@ -1901,40 +1902,50 @@ def encode(self, encoding, errors="strict"):

Examples
--------
>>> s = pd.Series(['1. Ant. ', '2. Bee!\n', '3. Cat?\t', np.nan])
>>> s = pd.Series(['1. Ant. ', '2. Bee!\n', '3. Cat?\t', np.nan, 10, True])
>>> s
0 1. Ant.
1 2. Bee!\n
2 3. Cat?\t
3 NaN
4 10
5 True
dtype: object

>>> s.str.strip()
0 1. Ant.
1 2. Bee!
2 3. Cat?
3 NaN
4 NaN
5 NaN
dtype: object

>>> s.str.lstrip('123.')
0 Ant.
1 Bee!\n
2 Cat?\t
3 NaN
4 NaN
5 NaN
dtype: object

>>> s.str.rstrip('.!? \n\t')
0 1. Ant
1 2. Bee
2 3. Cat
3 NaN
4 NaN
5 NaN
dtype: object

>>> s.str.strip('123.!? \n\t')
0 Ant
1 Bee
2 Cat
3 NaN
4 NaN
5 NaN
dtype: object
"""

Expand Down