I use this function to find if the pattern is in the column and replace it with the replacement but it does not give.
Can someone tell where I make the mistakes?
patterns = [
'15/19',
'14/11',
'HTP',
'VTP'
]
replacements = [
'S15/19',
'S11/14',
'HTP',
'VTP'
]
def formate_column(output_column, df, patterns, replacements):
for p, r in zip(patterns, replacements):
df = (
df.withColumn(output_column, F.when(F.col("column").contains(p), F.regexp_replace(F.col("column"), p, r)).otherwise(F.col("column")))
)
return df