title: pandas, renaming a multiindex column (order of data is changed)
body: <p>I do have following dataframe:</p>
  
  <pre><code>{'e1.data_280': {0: 10, 1: 20, 2: 30},
   'e1.data_603': {0: 7, 1: 8, 2: 9},
   'e2.data_280': {0: 30, 1: 20, 2: 10},
   'e2.data_603': {0: 8, 1: 9, 2: 1}}
  </code></pre>
  
  <p>after:</p>
  
  <pre><code>df.columns = df.columns.str.split('.', expand=True)
  </code></pre>
  
  <p>it looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/D9ZMt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9ZMt.png" alt="enter image description here"></a></p>
  
  <p>Now I would like to get rid of the phrase <code>data_</code>:</p>
  
  <p>get the three digits behind the underscore:</p>
  
  <pre><code>cols = [item.split('_')[1] for item in df.columns.get_level_values(1)]
  cols
  ['603', '280', '603', '280']
  </code></pre>
  
  <p>If I replace the old labels:</p>
  
  <pre><code>df.columns.set_levels(cols, level=1, inplace=True)
  </code></pre>
  
  <p>The data is changed:</p>
  
  <p><a href="https://i.stack.imgur.com/m1rE5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m1rE5.png" alt="enter image description here"></a></p>
  
  <p>I see that <code>cols</code> has more entries than the name of the multiindex at level 1:</p>
  
  <pre><code>MultiIndex(levels=[['e1', 'e2'], ['data_280', 'data_603']],
             labels=[[0, 0, 1, 1], [1, 0, 1, 0]])
  </code></pre>
  
  <p>But how can I rename the first level of multiindex columns in a dataframe ?</p>
  
  <p>EDIT: A workaround</p>
  
  <pre><code>df.unstack().reset_index()
  </code></pre>
  
  <p>together with renaming the column and splitting the column values works:</p>