StringMethods.strip(to_strip: str | None = None) SeriesOrIndex[source]#

Remove leading and trailing characters.

Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from left and right sides. Equivalent to str.strip().

to_stripstr or None, default None

Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.

Series/Index of str dtype

Returns Series or Index.

See also


Remove leading characters in Series/Index.


Remove trailing characters in Series/Index.


>>> import cudf
>>> s = cudf.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', None])
>>> s
0    1. Ant.
1    2. Bee!\n
2    3. Cat?\t
3         <NA>
dtype: object
>>> s.str.strip()
0    1. Ant.
1    2. Bee!
2    3. Cat?
3       <NA>
dtype: object
>>> s.str.strip('123.!? \n\t')
0     Ant
1     Bee
2     Cat
3    <NA>
dtype: object