pyspark.sql.functions.replace#
- pyspark.sql.functions.replace(src, search, replace=None)[source]#
Replaces all occurrences of search with replace.
Added in version 3.5.0.
- Parameters:
- src
Columnor str A column of string to be replaced. A column that evaluates to a string.
- search
Columnor str A column of string, If search is not found in str, str is returned unchanged. A column that evaluates to a string.
- replace
Columnor str, optional A column of string, If replace is not specified or is an empty string, nothing replaces the string that is removed from str. A column that evaluates to a string.
- src
Examples
>>> df = spark.createDataFrame([("ABCabc", "abc", "DEF",)], ["a", "b", "c"]) >>> df.select(replace(df.a, df.b, df.c).alias('r')).collect() [Row(r='ABCDEF')]
>>> df.select(replace(df.a, df.b).alias('r')).collect() [Row(r='ABC')]