title: Is it possible to do a loop and case in Pyspark?
body: <p>Is it possible to loop through some data in Pyspark and then based on a case statement come out with new values? (Since I've learned cases don't exist in Python).</p>
  
  <p>For example: if my table is</p>
  
  <p>DayofWeek</p>
  
  <pre><code>Monday
  Tuesday
  Monday
  Wednesday
  Monday
  </code></pre>
  
  <p>And my case statement is something like</p>
  
  <pre><code>Case
    When "DayOfWeek" is "Monday" then = 1
    When "DayOfWeek" is "Tuesday" then = 2
    When "DayofWeek" is "Wednesday" then =3
  </code></pre>
  
  <p>And the output would then be something like:</p>
  
  <p>DayNumber</p>
  
  <pre><code>1
  2
  1
  3
  1
  </code></pre>
  
  <p>I'm guessing I need to do some sort of loop - loop through each one and in that step of the loop apply the current value to a case statement - but I'm lost at how to accomplish this. Case isn't possible in Python? Should I do just el if?
  Should I use a case in SQL (Like when?)</p>