title: Spark Pivot String in PySpark
body: <p>I have a problem restructuring data using Spark. The original data looks like this:</p>
  
  <pre><code>df = sqlContext.createDataFrame([
      ("ID_1", "VAR_1", "Butter"),
      ("ID_1", "VAR_2", "Toast"),
      ("ID_1", "VAR_3", "Ham"),
      ("ID_2", "VAR_1", "Jam"),
      ("ID_2", "VAR_2", "Toast"),
      ("ID_2", "VAR_3", "Egg"),
  ], ["ID", "VAR", "VAL"])
  
  &gt;&gt;&gt; df.show()
  +----+-----+------+
  |  ID|  VAR|   VAL|
  +----+-----+------+
  |ID_1|VAR_1|Butter|
  |ID_1|VAR_2| Toast|
  |ID_1|VAR_3|   Ham|
  |ID_2|VAR_1|   Jam|
  |ID_2|VAR_2| Toast|
  |ID_2|VAR_3|   Egg|
  +----+-----+------+
  </code></pre>
  
  <p>This is the structure I try to achieve:</p>
  
  <pre><code>+----+------+-----+-----+
  |  ID| VAR_1|VAR_2|VAR_3|
  +----+------+-----+-----+
  |ID_1|Butter|Toast|  Ham|
  |ID_2|   Jam|Toast|  Egg|
  +----+------+-----+-----+
  </code></pre>
  
  <p>My idea was to use:</p>
  
  <pre><code>df.groupBy("ID").pivot("VAR").show()
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'GroupedData' object has no attribute 'show'
  </code></pre>
  
  <p>Any suggestions! Thanks!</p>