I am trying to check for a condition in pyspark dataframe and add values to a column like below:
DF:
cd id Location
A A A
A AA A
A AAA
A B B
A BB B
A BBB
Expected output:
cd id Location
A A A
A AA A
A AAA New_Loc
A B B
A BB B
A BBB New_Loc
I tried to populate using the below pyspark transformation
df_new = df.withColumn('Location',sf.when(df.cd == 'A' & (df.id isin(['AAA','BBB'])),'New_Loc').otherwise(df.Location))
When i try to execute this, I am getting the error: Py4JError: An error occured while calling o129.and. Trace: py4j.Py4JException: Method and ([class java.lang.string]) does not exist
Any idea whats this error?