title: Reshaping Pandas DataFrame with Repeated Column Index
body: <p>Suppose I have the following DataFrame:</p>
  
  <pre><code>&gt;&gt;&gt; cols = ['model', 'parameter', 'condition', 'value']
  &gt;&gt;&gt; df = pd.DataFrame([['BMW', '0-60', 'rain', '7'], ['BMW', '0-60', 'sun', '7'],
                     ['BMW','mpg', 'rain','25'], 
                     ['BMW', 'stars', 'rain','5'],
                     ['Toyota', '0-60', 'rain','9'], 
                     ['Toyota','mpg', 'rain','40'], 
                     ['Toyota', 'stars', 'rain','4']], columns=cols)
  
  &gt;&gt;&gt; df
      model parameter condition value
  0     BMW      0-60      rain     7
  1     BMW      0-60       sun     7
  2     BMW       mpg      rain    25
  3     BMW     stars      rain     5
  4  Toyota      0-60      rain     9
  5  Toyota       mpg      rain    40
  6  Toyota     stars      rain     4
  </code></pre>
  
  <p>This is a list of performance metrics for various cars at different conditions. This is a made up data set, of course, but its representative of my problem.</p>
  
  <p>What I ultimately want is to have observation for a given condition on its own row, and each metric on its own column. This would look something like this:</p>
  
  <pre><code>    parameter  condition  0-60   mpg    stars
       model        
  0     BMW       rain       7      25     5
  1     BMW       sun        7      NaN    NaN
  2     Toyota    rain       9      40     4
  </code></pre>
  
  <p>Note that I just made up the format above. I don't know if Pandas would generate something exactly like that, but that's the general idea. I would also of course transform the "condition" into a Boolean array and fill in the NaNs. </p>
  
  <p>My problem is that when I try to use the pivot method I get an error. I think this is because my "column" key is repeated (because I have BMW 0-60 stats for the rain and for the sun conditions).</p>
  
  <pre><code>df.pivot(index='model',columns='parameter')
  ValueError: Index contains duplicate entries, cannot reshape
  </code></pre>
  
  <p>Does anyone know of a slick way to do this? I'm finding a lot of these Pandas reshaping methods to be quite obtuse.</p>