title: Pandas MultiIndex manipulation
body: <p>I'm not very adept at Python, but I have a &quot;bandaid&quot; solution to a problem and trying to find out if there is a better way to do things. I have a dataframe of stocks I download from pandas_datareader. This gives me a MultiIndex df, and I'm trying to exact just the attributes that I want.</p>
  <p>The initial df from pandas_datareader results in the following structure:</p>
  <p><a href="https://i.stack.imgur.com/J6gzB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J6gzB.png" alt="enter image description here" /></a></p>
  <p>I'm interested in getting just the &quot;High&quot; and &quot;Closing&quot; prices in this structure. To achieve this, I have done the following:</p>
  <pre><code>  df.loc[:, ['High', 'Close']]
  </code></pre>
  <p>Which gives me:</p>
  <p><a href="https://i.stack.imgur.com/xgNUC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xgNUC.png" alt="enter image description here" /></a></p>
  <p>This is close to what I want, but not grouped by the stock, rather the attribute. To group the attribute by stock, I tried swapping the levels, and then specifying the columns I want:</p>
  <pre><code>newdf = df.swaplevel(axis='columns')
  newdf.loc[:, [('BHP.AX','High'),('BHP.AX','Close'),('S32.AX','Close'),('S32.AX','High')]]
  </code></pre>
  <p>This gives me the desired result, but seems a very &quot;hardcoded&quot; and inefficient way of doing this:
  <a href="https://i.stack.imgur.com/NwVt8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NwVt8.png" alt="enter image description here" /></a></p>
  <p>Is there a more generalized way I could go about doing this? I want to be able to just specify the attributes (e.g. Close, High etc) and the result to be for all stocks in there (grouped by stock rather than the attribute). This Multiindex is not making it easy for me so any help you can offer is appreciated.</p>