title: Rename Pandas Multiindex based on another column's name
body: <p>I've got a CSV file that is generated in a format I cannot change. The file has a multiindex: headers on two lines. The first line (higher level of index) has blanks when the value doesn't change.</p>
  
  <p>What my header looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/deMBn.jpg" alt="Header loos like this"></p>
  
  <p>What it actually comes down to and what I want:</p>
  
  <p><img src="https://i.stack.imgur.com/I2msf.jpg" alt="What the header actually is"></p>
  
  <p>I would like to be able to process it correctly in Python 2.7 with Pandas.</p>
  
  <p>I resulted to looping on the first level of index and if the value is blank, set it to be the same as the one on the left.</p>
  
  <p>I start by loading the dataframe in pandas:</p>
  
  <pre><code>df = pd.read_csv(myFile, header=[0,1], sep=',')
  df
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Qr136.jpg" alt="Dataframe loaded in Pandas"></p>
  
  <p>I've tried the following:</p>
  
  <pre><code>for i, val in enumerate(df.columns.values):
      if val[0][:7] == 'Unnamed':
          l.append([l[i-1][0], val[1]])
      else:
          l.append(val)
  </code></pre>
  
  <p>The list "l" I'm getting appears to be what I want:</p>
  
  <pre><code>[('Foo', 'A'),
   ['Foo', 'B'],
   ['Foo', 'C'],
   ('Bar', 'A'),
   ['Bar', 'B'],
   ['Bar', 'C']]
  </code></pre>
  
  <p>I've tried both:</p>
  
  <pre><code>df.columns = l 
  </code></pre>
  
  <p>Produces a non multiindex dataframe</p>
  
  <p><img src="https://i.stack.imgur.com/YG7hs.jpg" alt="Flat dataframe"></p>
  
  <pre><code>index = pd.MultiIndex.from_tuples(l)
  df.reindex(columns = index)
  </code></pre>
  
  <p>This one gives me the correct index, but values disappear.</p>
  
  <p><img src="https://i.stack.imgur.com/SbSt3.jpg" alt="Disappeared values"></p>
  
  <p>I'm getting a strong gut feeling that the entire approach I'm trying isn't very pythonic nor does it make sense to use a list then converted to a dict. Any idea how I can multiindex properly?</p>