title: Python / Pandas : concatenate two dataframes with multi index
body: <p>I have two dataframes with same index &amp; columns. (x, y)</p>
  
  <pre><code>&gt;&gt;&gt; x
      A   B
  0  A0  B0
  1  A1  B1
  
  &gt;&gt;&gt; y
      A   B
  0  A2  B2
  1  A3  B3
  </code></pre>
  
  <p>I found out how to concatenate two dataframes with multi-index as follows. (z)</p>
  
  <pre><code>&gt;&gt;&gt; z = pd.concat([x, y], keys=['x', 'y'], axis=1)
  &gt;&gt;&gt; z
      x       y
      A   B   A   B
  0  A0  B0  A2  B2
  1  A1  B1  A3  B3
  </code></pre>
  
  <p>But I want to make the following format of dataframe (target )</p>
  
  <pre><code>&gt;&gt;&gt; target
      A       B
      x   y   x   y
  0  A0  A2  B0  B2
  1  A1  A3  B1  B3
  </code></pre>
  
  <p>I have two questions</p>
  
  <ol>
  <li>Is there a nice way to get the 'target' dataframe directly from the x, y ?</li>
  <li>Is there a nice way to get the 'target' datafrme from z by changing the level of columns?</li>
  </ol>
  
  <p>Thank you for considering my questions.</p>