pyspark.pandas.Series.str.strip¶
-
str.
strip
(to_strip: Optional[str] = None) → ps.Series¶ 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()
.- Parameters
- to_stripstr
Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.
- Returns
- Series of objects
Examples
>>> s = ps.Series(['1. Ant.', '2. Bee!\t', None]) >>> s 0 1. Ant. 1 2. Bee!\t 2 None dtype: object
>>> s.str.strip() 0 1. Ant. 1 2. Bee! 2 None dtype: object
>>> s.str.strip('12.') 0 Ant 1 Bee!\t 2 None dtype: object
>>> s.str.strip('.!\t') 0 1. Ant 1 2. Bee 2 None dtype: object