Pandas Series str.rstrip(~)
方法刪除 Series 中每個字符串右側出現的指定字符的組合。
請注意,返回的是一個新係列,並且原始係列保持不變。
參數
1.to_strip
| str
或 None
| optional
每個字符串後麵出現的 to_strip
字符組合將被刪除。例如,如果 to_strip="ab"
,則 Aab
和 Aba
都將變為 A
。
默認情況下,尾隨空格(包括換行符和製表符)將被刪除。
返回值
新的 Series
或 Index
。
例子
基本用法
默認情況下,rstrip(~)
刪除尾隨空格(包括換行符和製表符):
s = pd.Series([" ","a a","\na","a\t"])
s_stripped = s.str.rstrip()
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(["Aab","Aba"])
s.str.rstrip("ab")
0 A
1 A
dtype: object
相關用法
- Python Pandas Series str replace方法用法及代碼示例
- 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 len方法用法及代碼示例
- Python Pandas Series str lower方法用法及代碼示例
- Python Pandas Series str strip方法用法及代碼示例
- Python Pandas Series str lstrip方法用法及代碼示例
- 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 | rstrip method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。