pandas.Series.str.lstrip #

系列.str。lstrip ( to_strip = None ) [来源] #

删除主要字符。

从左侧的系列/索引中的每个字符串中go除空格(包括换行符)或一组指定字符。将 Series 中的任何非字符串替换为 NaN。相当于str.lstrip()

参数
to_strip str 或 None,默认 None

指定要删除的字符集。这组字符的所有组合都将被删除。如果没有,则删除空格。

返回
对象的系列或索引

也可以看看

Series.str.strip

删除系列/索引中的前导和尾随字符。

Series.str.lstrip

删除系列/索引中的主要字符。

Series.str.rstrip

删除系列/索引中的尾随字符。

例子

>>> s = pd.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', np.nan, 10, True])
>>> s
0    1. Ant.
1    2. Bee!\n
2    3. Cat?\t
3          NaN
4           10
5         True
dtype: object
>>> s.str.strip()
0    1. Ant.
1    2. Bee!
2    3. Cat?
3        NaN
4        NaN
5        NaN
dtype: object
>>> s.str.lstrip('123.')
0    Ant.
1    Bee!\n
2    Cat?\t
3       NaN
4       NaN
5       NaN
dtype: object
>>> s.str.rstrip('.!? \n\t')
0    1. Ant
1    2. Bee
2    3. Cat
3       NaN
4       NaN
5       NaN
dtype: object
>>> s.str.strip('123.!? \n\t')
0    Ant
1    Bee
2    Cat
3    NaN
4    NaN
5    NaN
dtype: object