Skip to content

Commit 0add019

Browse files
Cheuktingmroeschke
authored andcommitted
DOC: update the pandas.Series.str.strip docstring (#20863)
* DOC: update the pandas.Series.str.strip docstring * DOC: update the pandas.Series.str.strip docstring * typo fixing and improve Index example * Fix PEP8 * Improve parameter explaination * Improve documentation, adding lstrip and rstrip example * simplify lstrip and rstrip * added np.nan example
1 parent 8594b7d commit 0add019

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

pandas/core/strings.py

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,12 +2557,66 @@ def encode(self, encoding, errors="strict"):
25572557
return self._wrap_result(result)
25582558

25592559
_shared_docs['str_strip'] = ("""
2560-
Strip whitespace (including newlines) from each string in the
2561-
Series/Index from %(side)s. Equivalent to :meth:`str.%(method)s`.
2560+
Remove leading and trailing characters.
2561+
2562+
Strip whitespaces (including newlines) or a set of specified characters
2563+
from each string in the Series/Index from %(side)s.
2564+
Equivalent to :meth:`str.%(method)s`.
2565+
2566+
Parameters
2567+
----------
2568+
to_strip : str or None, default None.
2569+
Specifying the set of characters to be removed.
2570+
All combinations of this set of characters will be stripped.
2571+
If None then whitespaces are removed.
25622572
25632573
Returns
25642574
-------
2565-
stripped : Series/Index of objects
2575+
Series/Index of objects
2576+
2577+
See Also
2578+
--------
2579+
Series.str.strip : Remove leading and trailing characters in Series/Index
2580+
Series.str.lstrip : Remove leading characters in Series/Index
2581+
Series.str.rstrip : Remove trailing characters in Series/Index
2582+
2583+
Examples
2584+
--------
2585+
>>> s = pd.Series(['1. Ant. ', '2. Bee!\n', '3. Cat?\t', np.nan])
2586+
>>> s
2587+
0 1. Ant.
2588+
1 2. Bee!\n
2589+
2 3. Cat?\t
2590+
3 NaN
2591+
dtype: object
2592+
2593+
>>> s.str.strip()
2594+
0 1. Ant.
2595+
1 2. Bee!
2596+
2 3. Cat?
2597+
3 NaN
2598+
dtype: object
2599+
2600+
>>> s.str.lstrip('123.')
2601+
0 Ant.
2602+
1 Bee!\n
2603+
2 Cat?\t
2604+
3 NaN
2605+
dtype: object
2606+
2607+
>>> s.str.rstrip('.!? \n\t')
2608+
0 1. Ant
2609+
1 2. Bee
2610+
2 3. Cat
2611+
3 NaN
2612+
dtype: object
2613+
2614+
>>> s.str.strip('123.!? \n\t')
2615+
0 Ant
2616+
1 Bee
2617+
2 Cat
2618+
3 NaN
2619+
dtype: object
25662620
""")
25672621

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

0 commit comments

Comments
 (0)