pyspark.sql.functions.translate

pyspark.sql.functions.translate(srcCol: ColumnOrName, matching: str, replace: str) → pyspark.sql.column.Column[source]

A function translate any character in the srcCol by a character in matching. The characters in replace is corresponding to the characters in matching. Translation will happen whenever any character in the string is matching with the character in the matching.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
srcColColumn or str

Source column or strings

matchingstr

matching characters.

replacestr

characters for replacement. If this is shorter than matching string then those chars that don’t have replacement will be dropped.

Returns
Column

replaced value.

Examples

>>> spark.createDataFrame([('translate',)], ['a']).select(translate('a', "rnlt", "123") \
...     .alias('r')).collect()
[Row(r='1a2s3ae')]