I have a dataframe:
"people" "other"
father ...
mother
cat
brother
dog
I'm going to insert new column, if column people contains word in specific array then modify the content with that of other array, else word will remain the same:
array=['father','mother','brother']
array_new=['dad','mum','bro']
"people" "other" "new"
father ... dad
mother mum
cat cat
brother bro
dog dog
I think to use this:
expression = ("CASE " +"".join(["WHEN people LIKE '{}' THEN '{}' ".format(val,array_new[array.index(val)](val)) for val in array]) +"ELSE 'None' END")
df_pyspark = df_pyspark.withColumn("new", functions.expr(expression))
I should change the else condition, but I don't know how to do it, for copy the same word in the else condition.