title: Compare headers of dataframes in pandas
body: <p>I am trying to compare the headers of two pandas dataframes and filter the columns that match.
  df1 is my big dataframe with two headers, df2 is sort of a dictionary where I have saved every column header I will need from df1.</p>
  
  <p>So if df1 is something like this:</p>
  
  <pre><code>    A         B         C         D
      a         b         c         d
   0.469112 -0.282863 -1.509059 -1.135632
   1.212112 -0.173215  0.119209 -1.044236
  -0.861849 -2.104569 -0.494929  1.071804
   0.721555 -0.706771 -1.039575  0.271860
  -0.424972  0.567020  0.276232 -1.087401
  -0.673690  0.113648 -1.478427  0.524988
  </code></pre>
  
  <p>and df2 is something like this:</p>
  
  <pre><code>   B         D         E
  </code></pre>
  
  <p>I need to get the output:</p>
  
  <pre><code>     B          D
   -0.282863  -1.135632
   -0.173215  -1.044236
   -2.104569   1.071804
   -0.706771   0.271860
    0.567020  -1.087401
    0.113648   0.524988
  </code></pre>
  
  <p>and also a list of the header elements that were not matching:</p>
  
  <pre><code>A      C
  </code></pre>
  
  <p>as well as elements missing from df1:</p>
  
  <pre><code>E
  </code></pre>
  
  <p>So far I have tried the iloc command and a lot of different suggestions here on stackoverflow for comparing rows. Since I am comparing the headers though it was not possible.</p>
  
  <p>EDIT: I have tried</p>
  
  <pre><code>df1.columns.intersection(df2.columns)
  </code></pre>
  
  <p>but the result is:</p>
  
  <pre><code>MultiIndex(levels=[[], []],
             labels=[[], []])
  </code></pre>
  
  <p>Is this because of the multiple headers?</p>