PySpark: withColumn() with two conditions and three outcomes
<p>I am working with Spark and PySpark. I am trying to achieve the result equivalent to the following pseudocode:</p>

<pre class="lang-py prettyprint-override"><code>df = df.withColumn('new_column', 
    IF fruit1 == fruit2 THEN 1, ELSE 0. IF fruit1 IS NULL OR fruit2 IS NULL 3.)
</code></pre>

<p>I am trying to do this in PySpark but I'm not sure about the syntax. Any pointers? I looked into <code>expr()</code> but couldn't get it to work.</p>

<p>Note that <code>df</code> is a <code>pyspark.sql.dataframe.DataFrame</code>.</p>