mars.dataframe.Series.str.strip#

Series.str.strip(to_strip=None)#

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_strip (str 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 or Index of object

参见

Series.str.strip

Remove leading and trailing characters in Series/Index.

Series.str.lstrip

Remove leading characters in Series/Index.

Series.str.rstrip

Remove trailing characters in Series/Index.

示例

>>> import mars.tensor as mt
>>> import mars.dataframe as md
>>> s = md.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', mt.nan])
>>> s.execute()
0    1. Ant.
1    2. Bee!\n
2    3. Cat?\t
3          NaN
dtype: object
>>> s.str.strip().execute()
0    1. Ant.
1    2. Bee!
2    3. Cat?
3        NaN
dtype: object
>>> s.str.lstrip('123.').execute()
0    Ant.
1    Bee!\n
2    Cat?\t
3       NaN
dtype: object
>>> s.str.rstrip('.!? \n\t').execute()
0    1. Ant
1    2. Bee
2    3. Cat
3       NaN
dtype: object
>>> s.str.strip('123.!? \n\t').execute()
0    Ant
1    Bee
2    Cat
3    NaN
dtype: object