title: pyspark conditions on multiple columns and returning new column
body: <p>I am using spark 2.1 and scripting is pyspark. Please help me with this as I am stuck up here . </p>
  
  <p>Problem statement: To create new columns based on conditions on multiple columns</p>
  
  <p>Input <code>dataframe</code> is below</p>
  
  <pre><code>FLG1 FLG2 FLG3
  
  T     F     T
  
  F     T     T
  
  T     T     F
  </code></pre>
  
  <p>Now I need to create one new column as FLG and my conditions would be like if <code>FLG1==T&amp;&amp;(FLG2==F||FLG2==T)</code> my <code>FLG</code> has to be <code>T</code> else <code>F</code></p>
  
  <p>Considered above <code>dataframe</code> as <code>DF</code></p>
  
  <p>below is my code snippet which was tried</p>
  
  <pre><code>DF.withColumn("FLG",DF.select(when(FLG1=='T' and (FLG2=='F' or FLG2=='T','F').otherwise('T'))).show()
  </code></pre>
  
  <p>Didn't work I was getting name when is not defined</p>
  
  <p>Please help me in crossing this hurdle</p>