Skip to content

Commit fd3eda2

Browse files
committed
Improve documentation, adding lstrip and rstrip example
1 parent e6fe921 commit fd3eda2

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

pandas/core/strings.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,46 +2159,52 @@ def encode(self, encoding, errors="strict"):
21592159
21602160
Parameters
21612161
----------
2162-
to_strip : str, optional
2162+
to_strip : str or None, default None (whitespaces are removed)
21632163
Specifying the set of characters to be removed.
21642164
All combinations of this set of characters will be stripped.
2165-
Default value is None, which means whaitspaces will be removed.
21662165
21672166
Returns
21682167
-------
2169-
stripped : Series/Index of objects
2168+
Series/Index of objects
21702169
21712170
See Also
21722171
--------
2173-
str.slice : Slice substrings from each element in the Series/Index
2172+
Series.str.strip : Remove leading and trailing characters in Series/Index
2173+
Series.str.lstrip : Remove leading characters in Series/Index
2174+
Series.str.rstrip : Remove trailing characters in Series/Index
21742175
21752176
Examples
21762177
--------
2177-
Stripping whitespaces for Series
2178-
2179-
>>> s = pd.Series([' ant', 'bee ', ' cat '])
2180-
2178+
>>> s = pd.Series(['1. Ant. ', '2. Bee!\n', '3. Cat?\t'])
21812179
>>> s
2182-
0 ant
2183-
1 bee
2184-
2 cat
2180+
0 1. Ant.
2181+
1 2. Bee!\n
2182+
2 3. Cat?\t
21852183
dtype: object
21862184
21872185
>>> s.str.strip()
2188-
0 ant
2189-
1 bee
2190-
2 cat
2186+
0 1. Ant.
2187+
1 2. Bee!
2188+
2 3. Cat?
21912189
dtype: object
21922190
2193-
Stripping a set of characters for Index
2194-
2195-
>>> idx = pd.Index(['1.ant ','2._bee__','3. cat_'])
2191+
>>> s.str.strip('123.!? \n\t')
2192+
0 Ant
2193+
1 Bee
2194+
2 Cat
2195+
dtype: object
21962196
2197-
>>> idx
2198-
Index(['1.ant ', '2._bee__', '3. cat_'], dtype='object')
2197+
>>> s.str.lstrip('123.!? \n\t')
2198+
0 Ant.
2199+
1 Bee!\n
2200+
2 Cat?\t
2201+
dtype: object
21992202
2200-
>>> idx.str.strip('123._ ')
2201-
Index(['ant', 'bee', 'cat'], dtype='object')
2203+
>>> s.str.rstrip('123.!? \n\t')
2204+
0 1. Ant
2205+
1 2. Bee
2206+
2 3. Cat
2207+
dtype: object
22022208
""")
22032209

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

0 commit comments

Comments
 (0)