Dropping multilevel columns from lists of dictionaries in pandas
<p>I have a dataframe with multilevel columns, like the one in the following MWE:</p>

<pre><code>df = pd.DataFrame([[1,2],[3,4]], columns=[['a','c'],['b','d']], index=['one','two'])
df.columns.names = ['aa', 'bb']
</code></pre>

<p>Which looks like this:</p>

<pre><code>In [267]: df
Out[267]: 
aa   a  c
bb   b  d
one  1  2
two  3  4
</code></pre>

<p>I also have a list of dictionaries like the following:</p>

<pre><code>to_keep = [{'aa':'a', 'bb':'b'}, {'aa':'q', 'bb':'d'}]
</code></pre>

<p>What I'm looking to do:</p>

<p>If the multilevel column labels are in the <code>to_keep</code> list then keep them in <code>df</code>, otherwise drop them from the df.</p>

<p>So for <code>df</code> and <code>to_keep</code> above the resulting dataframe would look like:</p>

<pre><code>aa   a
bb   b
one  1
two  3
</code></pre>

<p>as <code>{'aa':'c', 'bb':'d'}</code> is not contained within <code>to_keep</code>. Is this possible?</p>