I have a pysaprk dataframe like:
I want to add another column like flag and if firstname contains value of middle name then add 1 to flag and if middle name contains value of last name then add flag as 2 else 0
output should be like this;
how to achieve this using pyspark
i tried
from pyspark.sql.functions import when
Flag_df = df.withColumn('flag',when(final_df['firstname'].contains(final_df['middlename']),1).otherwise(0))
here I could only achieve 1 and 0.