title: Compare two columns to create a new column in Spark DataFrame
body: <p>I have a Spark DataFrame that has 2 columns, I am trying to create a new column using the other two columns with the when otherwise operation.</p>
  
  <pre><code>df_newcol = df.withColumn("Flag", when(col("a") &lt;= lit(ratio1) | col("b") &lt;= lit(ratio1), 1).otherwise(2))
  </code></pre>
  
  <p>But this throws an error</p>
  
  <pre><code>ValueError: Cannot convert column into bool: please use '&amp;' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions.
  </code></pre>
  
  <p>I have used when and otherwise previously with one column, while using it with multiple columns do we have to write the logic differently.</p>
  
  <p>Thanks.</p>