pandas.Series.str.removeprefix#
- Series.str.removeprefix(prefix)[源代码]#
- 从对象系列中移除前缀。 - 如果前缀不存在,将返回原始字符串。 - 参数:
- 前缀str
- 移除字符串的前缀。 
 
- 返回:
- 系列/索引: 对象
- 移除给定前缀的序列或索引。 
 
 - 参见 - Series.str.removesuffix
- 从对象系列中移除后缀。 
 - 示例 - >>> 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