replace
Replaces all occurrences of search with replace.
For the corresponding Databricks SQL function, see replace function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.replace(src=<src>, search=<search>, replace=<replace>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| A column of string to be replaced. |
|
| A column of string, If |
|
| A column of string, If |
Examples
Python
df = spark.createDataFrame([("ABCabc", "abc", "DEF",)], ["a", "b", "c"])
df.select(replace(df.a, df.b, df.c).alias('r')).collect()
Output
[Row(r='ABCDEF')]
Python
df.select(replace(df.a, df.b).alias('r')).collect()
Output
[Row(r='ABC')]