pandas.Series.str.removesuffix#

Series.str.removesuffix(suffix)[源代码]#

从对象 Series 中移除后缀。

如果不存在后缀,则返回原始字符串。

Parameters:
suffixstr

移除字符串的后缀。

Returns:
Series/Index: 对象

移除给定后缀后的 Series 或 Index。

参见

Series.str.removeprefix

从对象 Series 中移除前缀。

Examples

>>> 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