pyspark when otherwise multiple conditions

df5.withColumn("new_column", when(col("code") == "a" | col("code") == "d", "A")
      .when(col("code") == "b" & col("amt") == "4", "B")
      .otherwise("A1")).show()

Here is what the above code is Doing:
1. We’re creating a new column called “new_column”
2. We’re using the when function to check if the code is equal to “a” or “d”
3. If the code is equal to “a” or “d”, we’re setting the value of the new column to “A”
4. If the code is equal to “b” and the amt is equal to “4”, we’re setting the value of the new column to “B”
5. Otherwise, we’re setting the value of the new column to “A1”