Skip to content

Commit a54a326

Browse files
committed
DOC: update the pandas.Series.str.strip docstring
1 parent 563a6ad commit a54a326

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

pandas/core/strings.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,12 +2151,45 @@ def encode(self, encoding, errors="strict"):
21512151
return self._wrap_result(result)
21522152

21532153
_shared_docs['str_strip'] = ("""
2154-
Strip whitespace (including newlines) from each string in the
2155-
Series/Index from %(side)s. Equivalent to :meth:`str.%(method)s`.
2154+
Remove leading and trailing characters.
2155+
2156+
Strip whitespaces (including newlines) or a set of specified characters
2157+
from each string in the Series/Index from %(side)s.
2158+
Equivalent to :meth:`str.%(method)s`.
2159+
2160+
Parameters
2161+
----------
2162+
to_strip : str
2163+
specifying the set of characters to be removed.
2164+
All combinations of this set of characters will be stripped.
2165+
Default value is None, which means whaitspaces will be removed.
21562166
21572167
Returns
21582168
-------
21592169
stripped : Series/Index of objects
2170+
2171+
Examples
2172+
--------
2173+
Striping whitespaces for Series
2174+
2175+
>>>s = pd.Series([' ant', 'bee ', ' cat '])
2176+
>>>s
2177+
0 ant
2178+
1 bee
2179+
2 cat
2180+
dtype: object
2181+
>>>s.str.strip()
2182+
0 ant
2183+
1 bee
2184+
2 cat
2185+
dtype: object
2186+
2187+
Striping a set of characters for Index
2188+
>>>df = pd.DataFrame(index=['1.ant ','2._bee__','3. cat_'])
2189+
>>>pd.index
2190+
Index(['1.ant ', '2._bee__', '3. cat_'], dtype='object')
2191+
>>>df.index.str.strip('123._ ')
2192+
Index(['ant', 'bee', 'cat'], dtype='object')
21602193
""")
21612194

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

0 commit comments

Comments
 (0)