I have a dataframe which consists of two columns
+--------------+------------+
| A| B|
+--------------+------------+
| [b, c]| [a, b, c]|
| [a]| [c, d]|
| [a, c]| [b, c, e]|
| [b, c]| [a, b]|
| [a]| [a, d, e]|
| [a, c]| [b]|
+--------------+------------+
Schema:
|-- A: string (nullable = true)
|-- B: array (nullable = true)
| |-- element: string (containsNull = true)
I want to add a new column which must be O if the intersection of A and B is empty list ([]) and 1 otherwise. I tried the code below but it seem incorrect at all
df.withColumn('Check', when (list((set(col('A'))&set(col('B')))) !=[] , 0).otherwise(1)).show()
Thank you for your help