maxframe.dataframe.Series.str.translate#

Series.str.translate(table)#

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

This method is equivalent to the standard str.translate() method for strings. It maps each character in the string to a new character according to the translation table provided. Unmapped characters are left unchanged, while characters mapped to None are removed.

参数:

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

返回:

A new Series or Index with translated strings.

返回类型:

Series or Index

参见

Series.str.replace

Replace occurrences of pattern/regex in the Series with some other string.

Index.str.replace

Replace occurrences of pattern/regex in the Index with some other string.

示例

>>> import maxframe.dataframe as md
>>> ser = md.Series(["El niño", "Françoise"])
>>> mytable = str.maketrans({"ñ": "n", "ç": "c"})
>>> ser.str.translate(mytable).execute()
0   El nino
1   Francoise
dtype: str