title: Pandas column values to columns?
body: <p>I've seen a few variations on the theme of exploding a column/series into multiple columns of a Pandas dataframe, but I've been trying to do something and not really succeeding with the existing approaches.</p>
  
  <p>Given a DataFrame like so:</p>
  
  <pre><code>    key       val
  id
  2   foo   oranges
  2   bar   bananas
  2   baz    apples
  3   foo    grapes
  3   bar     kiwis
  </code></pre>
  
  <p>I want to convert the items in the <code>key</code> series into columns, with the <code>val</code> values serving as the values, like so:</p>
  
  <pre><code>        foo        bar        baz
  id
  2   oranges    bananas     apples
  3    grapes      kiwis        NaN
  </code></pre>
  
  <p>I feel like this is something that should be relatively straightforward, but I've been bashing my head against this for a few hours now with increasing levels of convolution, and no success.</p>