Pandas Series str.lstrip(~) 方法刪除 Series 中每個字符串左側出現的指定字符的組合。
請注意,返回的是一個新係列,並且原始係列保持不變。
參數
1.to_strip | str 或 None | optional
每個字符串前麵出現的 to_strip 字符組合將被刪除。例如,如果 to_strip="ab" ,則 abA 和 baA 都將變為 A 。
默認情況下,前導空格(包括換行符和製表符)將被刪除。
返回值
新的 Series 或 Index 。
例子
基本用法
默認情況下,lstrip(~) 刪除前導空格(包括換行符和製表符):
s = pd.Series([" ","a a","\na","\ta"])
s_stripped = s.str.lstrip()
s_stripped
0
1 a a
2 a
3 a
dtype: object
為了確認空格確實已被刪除,我們打印每個字符串的長度:
s_stripped.str.len()
0 0
1 3
2 1
3 1
dtype: int64
指定to_strip
要刪除前麵的字符組合"ab":
s = pd.Series(["abA","baA"])
s.str.lstrip("ab")
0 A
1 A
dtype: object
在這裏,請注意 "baA" 如何被剝離為 "A" - 這是因為指定字符的組合被剝離(在本例中為 "ab" 和 "ba")。
相關用法
- Python Pandas Series str len方法用法及代碼示例
- Python Pandas Series str lower方法用法及代碼示例
- Python Pandas Series str extractall方法用法及代碼示例
- Python Pandas Series str split方法用法及代碼示例
- Python Pandas Series str center方法用法及代碼示例
- Python Pandas Series str pad方法用法及代碼示例
- Python Pandas Series str extract方法用法及代碼示例
- Python Pandas Series str replace方法用法及代碼示例
- Python Pandas Series str strip方法用法及代碼示例
- Python Pandas Series str rstrip方法用法及代碼示例
- Python Pandas Series string contains方法用法及代碼示例
- Python Pandas Series to_list方法用法及代碼示例
- Python Pandas Series between方法用法及代碼示例
- Python Pandas Series map方法用法及代碼示例
- Python Pandas Series hasnans屬性用法及代碼示例
- Python Pandas Series is_monotonic屬性用法及代碼示例
- Python Pandas Series to_frame方法用法及代碼示例
- Python Pandas Series zfill方法用法及代碼示例
- Python Pandas Series argmax方法用法及代碼示例
- Python Pandas Series is_monotonic_increasing屬性用法及代碼示例
- Python Pandas Series is_unique屬性用法及代碼示例
- Python Pandas Series argmin方法用法及代碼示例
- Python Pandas Series value_counts方法用法及代碼示例
- Python Pandas Series is_monotonic_decreasing屬性用法及代碼示例
- Python Pandas Series.cumsum()用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 Pandas Series str | lstrip method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
