title: Python Pandas Dataframes : use rows values to create columns
body: <p>I am attempting to replicate <a href="http://vita.had.co.nz/papers/tidy-data.pdf" rel="nofollow noreferrer">this article</a> in python, as a general way to improve my pandas skills.</p>
  
  <p>Right now, I am facing the following issue. Page 11 of that document you'll see table12(a) and table2(b). I found the way to get from table11 to table 12(a), but now I am stuck.</p>
  
  <p>I have the following dataframe:</p>
  
  <pre><code>    id  date    element value
  12  MX17004 2010-02-02  tmax    27.3
  13  MX17004 2010-02-02  tmin    14.4
  22  MX17004 2010-02-03  tmax    24.1
  23  MX17004 2010-02-03  tmin    14.4
  44  MX17004 2010-03-05  tmax    32.1
  45  MX17004 2010-03-05  tmin    14.2
  </code></pre>
  
  <p>How could I use it to get a "tmax" and a "tmin" columns ?</p>
  
  <p>Of course I could use a for loop, but I read somewhere that every time you find yourself doing complex code when manipulating dataframes, a function already exists that does what you want to do.</p>
  
  <p>My best attempt so far :</p>
  
  <pre><code>weather_molten.pivot(index='date', columns='element', values='value')
  </code></pre>
  
  <p>result : </p>
  
  <p><a href="https://i.stack.imgur.com/4TtZq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4TtZq.png" alt="enter image description here"></a></p>
  
  <p>As you can see, I now have a multiindex DF (quite far from the result in the article), I don't have the 'id' column anymore...</p>
  
  <p>Any idea ?</p>
  
  <p>Thank you for your time ! </p>