title: When clause in pyspark gives an error "name 'when' is not defined"
body: <p>With the below code I am getting an error message, name 'when' is not defined.  </p>
  
  <pre><code>voter_df = voter_df.withColumn('random_val',
  when(voter_df.TITLE == 'Councilmember', F.rand())
  .when(voter_df.TITLE == 'Mayor', 2)
  .otherwise(0))
  </code></pre>
  
  <p>Add a column to voter_df named random_val with the results of the F.rand() method for any voter with the title Councilmember. Set random_val to 2 for the Mayor. Set any other title to the value 0</p>