title: Pandas; tricky pivot table
body: <p>I have a pandas dataframe that I need to reshape/pivot. How to do it just seems beyond me at the moment. The dataframe looks like this:</p>
  
  <pre><code>Ref Statistic Val1 Val2 Val3 Val4
   0   Mean       0    1    2    3
   0   Std        0.1  0.1  0.1  0.1
   1   Mean       0    1    2    3
   1   Std        0.1  0.1  0.1  0.1
   2   Mean       0    1    2    3
   2   Std        0.1  0.1  0.1  0.1
  </code></pre>
  
  <p>And I'm aiming to get to this:</p>
  
  <pre><code>Ref Values Mean Std
   0    Val1   0  0.1
   0    Val2   1  0.1
   0    Val3   2  0.1
   0    Val4   3  0.1
   1    Val1   0  0.1
   1    Val2   1  0.1
   1    Val3   2  0.1
   1    Val4   3  0.1
   2    Val1   0  0.1
   2    Val2   1  0.1
   2    Val3   2  0.1
   2    Val4   3  0.1
  </code></pre>
  
  <p>It looks like this requires more than one pivot or a combination of pivot and groupby, but I'm having no luck...</p>
  
  <p>Any ideas?</p>