title: Pyspark: Equivalent of np.where
body: <p>What is the equivalent of this operation in Pyspark?</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  df = pd.DataFrame({'Type':list('ABBC'), 'Set':list('ZZXY')})
  df['color'] = np.where(df['Set']=='Z', 'green', 'red')
  print(df)
  </code></pre>
  
  <p><strong>output</strong></p>
  
  <pre><code>   Set Type  color
  0   Z    A  green
  1   Z    B  green
  2   X    B    red
  3   Y    C    red
  </code></pre>