title: Understanding pandas multi-index and double brackets
body: <p>I am trying to understand multi-indexing. I have found some very good links (<a href="https://jakevdp.github.io/PythonDataScienceHandbook/03.05-hierarchical-indexing.html" rel="nofollow noreferrer">here by Jake VanderPlas</a> and <a href="https://www.somebits.com/~nelson/pandas-multiindex-slice-demo.html" rel="nofollow noreferrer">here by Nelson Minar</a>) but I am not able to grasp the concept. </p>
  
  <p>I do have some specific questions. Specifically, if we talk about this data - </p>
  
  <pre><code>import pandas as pd
  
  # hierarchical indices and columns
  index = pd.MultiIndex.from_product([[2013, 2014], [1, 2]],
                                     names=['year', 'visit'])
  columns = pd.MultiIndex.from_product([['Bob', 'Guido', 'Sue'], ['HR', 'Temp']],
                                       names=['subject', 'type'])
  
  # mock some data
  data = np.round(np.random.randn(4, 6), 1)
  data[:, ::2] *= 10
  data += 37
  
  # create the DataFrame
  health_data = pd.DataFrame(data, index=index, columns=columns)
  </code></pre>
  
  <p>Then:</p>
  
  <ol>
  <li>Why/how does <code>health_data.loc[:,'Guido']</code> removes the top column
  index whereas <code>health_data.loc[:,['Guido']]</code> preserves it.  </li>
  <li>Why do <code>health_data.loc[:, [('Bob', 'HR')]]</code> and <code>health_data.loc[:,
  ('Bob', 'HR')]</code> work as intended (assuming answer to question 1 is
  clear) but <code>health_data.loc[:, ['Bob', 'HR']]</code> gives an extra
  column.</li>
  <li>If I define <code>idx = pd.IndexSlice</code> then why <code>health_data.loc[:,[idx['Bob','HR']]]</code> returns the intended output but <code>health_data.loc[:,list(idx['Bob','HR'])]</code> returns the extra column</li>
  </ol>
  
  <p>As my questions arose from my lack of understanding of multi-index, any links which explains them in detail will be help as well. I have seen some of the SO questions and answers (<a href="https://stackoverflow.com/questions/33417991/pandas-why-are-double-brackets-needed-to-select-column-after-boolean-indexing?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">this one</a> helps a bit) but most of them are very specific and I could not find one that talks about in general about double bracket concept. </p>