title: PySpark Pivoting
body: <p>I want to use PySpark to pivot data from a number of tables but i need to do it in a strange way. Please see below for an example.</p>
  
  <p>Original table:</p>
  
  <pre><code>Vehicle_id | Owner_ID    | Vehicle_Buy_Date
  --------------------------------------------
  1          | 1           | 01/01/2015
  1          | 2           | 01/10/2014
  2          | 1           | 10/10/2016
  </code></pre>
  
  <p>End result:</p>
  
  <pre><code>Vehicle_id | Owner_1_Buy_Date | Owner_2_Buy_Date
  ------------------------------------------------
  1          |01/01/2015        |01/10/2014
  2          |10/10/2016        |NULL
  </code></pre>
  
  <p>I understand that this is an unusual question to ask, as this isn't mostly done on database tables.</p>
  
  <p>Is there any way of doing this type of pivoting in PySpark?</p>