title: How to write nested if else in pyspark?
body: <p>I have a pyspark dataframe and I want to achieve the following conditions:</p>
  <pre><code>if col1 is not none:
      if col1 &gt; 17:
         return False
      else:
         return True
      return None 
  </code></pre>
  <p>I have implemented it in the following way:</p>
  <pre><code>out = out.withColumn('col2', out.withColumn(
          'col2', when(col('col1').isNull(), None).otherwise(
              when(col('col1') &gt; 17, False).otherwise(True)
          )))
  </code></pre>
  <p>However when I run this I achieve the following error :</p>
  <pre><code>  assert isinstance(col, Column), &quot;col should be Column&quot;
  AssertionError: col should be Column
  </code></pre>
  <p>Any ideas what I might be doing wrong.</p>