title: Change the order of index in pandas DataFrame with multiindex
body: <p>I am trying to find a straightforward way to change the order of values in a pandas DatafFrame multiindex. To illustrate what I mean, suppose we have a DataFrame with multiindex define as follows:</p>
  
  <pre><code>index = pd.MultiIndex(levels=[[u'C', u'D', u'M'], [u'C', u'D', u'M']],
             labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]],
             names=[u'level0', u'level1'])
  
  df = pd.DataFrame(np.random.randint(10,size=(9,3)),index=index,columns=['C','M','D'])
  </code></pre>
  
  <p>So we have a DataFrame df as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/veRyF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/veRyF.png" alt="enter image description here"></a></p>
  
  <p>What I am trying to do is to change the sequence of the Multiindex from "C D M" (which is ordered alphabetically) to "C M D" in both level0 and level1. I have tried to use pd.reindex, but have not found an easy way to achieve this goal.</p>
  
  <p>Jezrael gave an answer below which gives the correct display:</p>
  
  <pre><code>L = list('CMD')
  mux = pd.MultiIndex.from_product([L, L], names=df.index.names)
  df = df.reindex(mux)
  print (df)
  </code></pre>
  
  <p>However, what I need is that the levels of the index are in the order of "C M D" as well. If we check df.index, we get the following:</p>
  
  <pre><code>MultiIndex(levels=[[u'C', u'D', u'M'], [u'C', u'D', u'M']],
             labels=[[0, 0, 0, 2, 2, 2, 1, 1, 1], [0, 2, 1, 0, 2, 1, 0, 2, 1]],
             names=[u'level0', u'level1'])
  </code></pre>
  
  <p>Note the "levels" are still in the order of "C D M". What I want is such that when I use df.unstack(), I still get the index in the order of "C M D". Sorry for not making this clear.</p>