pyspark.sql.functions.replace¶
- 
pyspark.sql.functions.replace(src: ColumnOrName, search: ColumnOrName, replace: Optional[ColumnOrName] = None) → pyspark.sql.column.Column[source]¶
- Replaces all occurrences of search with replace. - New in version 3.5.0. - Parameters
- srcColumnor str
- A column of string to be replaced. 
- searchColumnor str
- A column of string, If search is not found in str, str is returned unchanged. 
- replaceColumnor 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. 
 
- 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')]