pandas.Series.str.translate#

Series.str.translate(table)[源代码]#

通过给定的映射表映射字符串中的所有字符。

等同于标准的 str.translate()

Parameters:
tabledict

Table 是一个 Unicode 序数到 Unicode 序数、字符串或 None 的映射。未映射的字符保持不变。映射为 None 的字符将被删除。str.maketrans() 是用于创建转换表的辅助函数。

Returns:
Series 或 Index

Examples

>>> ser = pd.Series(["El niño", "Françoise"])
>>> mytable = str.maketrans({'ñ': 'n', 'ç': 'c'})
>>> ser.str.translate(mytable)
0   El nino
1   Francoise
dtype: object