pandas.Series.str.removesuffix #
- 系列.str。删除后缀( suffix ) [来源] #
从对象系列中删除后缀。
如果后缀不存在,则返回原始字符串。
- 参数:
- 后缀字符串
删除字符串的后缀。
- 返回:
- 系列/索引:对象
已删除给定后缀的系列或索引。
也可以看看
Series.str.removeprefix
从对象系列中删除前缀。
例子
>>> s = pd.Series(["str_foo", "str_bar", "no_prefix"]) >>> s 0 str_foo 1 str_bar 2 no_prefix dtype: object >>> s.str.removeprefix("str_") 0 foo 1 bar 2 no_prefix dtype: object
>>> s = pd.Series(["foo_str", "bar_str", "no_suffix"]) >>> s 0 foo_str 1 bar_str 2 no_suffix dtype: object >>> s.str.removesuffix("_str") 0 foo 1 bar 2 no_suffix dtype: object