pandas.Series.str.lstrip#
- Series.str.lstrip(to_strip=None)[源代码]#
删除前导字符。
从左侧删除序列/索引中每个字符串中的空格(包括换行符)或一组指定字符。将串联中的任何非字符串替换为NAN。相当于
str.lstrip()
。- 参数
- to_strip字符串或无,默认为无
指定要删除的字符集。这组字符的所有组合都将被剥离。如果没有,则删除空格。
- 退货
- 对象的系列或索引
参见
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