title: Selecting rows from a Pandas dataframe with a compound (hierarchical) index
body: <p>I'm suspicious that this is trivial, but I yet to discover the incantation that will let me select rows from a Pandas dataframe based on the values of a hierarchical key. So, for example, imagine we have the following dataframe:</p>
  
  <pre><code>import pandas
  df = pandas.DataFrame({'group1': ['a','a','a','b','b','b'],
                         'group2': ['c','c','d','d','d','e'],
                         'value1': [1.1,2,3,4,5,6],
                         'value2': [7.1,8,9,10,11,12]
  })
  df = df.set_index(['group1', 'group2'])
  </code></pre>
  
  <p>df looks as we would expect: </p>
  
  <p><img src="https://i.stack.imgur.com/VGwOg.png" alt="enter image description here"></p>
  
  <p>If df were not indexed on group1 I could do the following:</p>
  
  <pre><code>df['group1' == 'a']
  </code></pre>
  
  <p>But that fails on this dataframe with an index. So maybe I should think of this like a Pandas series with a hierarchical index:</p>
  
  <pre><code>df['a','c']
  </code></pre>
  
  <p>Nope. That fails as well. </p>
  
  <p>So how do I select out all the rows where:</p>
  
  <ol>
  <li>group1 == 'a'</li>
  <li>group1 == 'a' &amp; group2 == 'c'</li>
  <li>group2 == 'c'</li>
  <li>group1 in ['a','b','c']</li>
  </ol>