title: MultiIndex-based indexing in pandas
body: <p>If I define a hierarchically-indexed dataframe like this:</p>
  
  <pre><code>import itertools
  import pandas as pd
  import numpy as np
  a = ('A', 'B')
  i = (0, 1, 2)
  b = (True, False)
  idx = pd.MultiIndex.from_tuples(list(itertools.product(a, i, b)),
                                  names=('Alpha', 'Int', 'Bool'))
  df = pd.DataFrame(np.random.randn(len(idx), 7), index=idx,
                    columns=('I', 'II', 'III', 'IV', 'V', 'VI', 'VII'))
  </code></pre>
  
  <p>the contents look like this:</p>
  
  <pre><code>In [19]: df
  Out[19]: 
                          I        II       III        IV         V        VI       VII
  Alpha Int Bool                                                                       
  A     0   True  -0.462924  1.210442  0.306737  0.325116 -1.320084 -0.831699  0.892865
            False -0.850570 -0.949779  0.022074 -0.205575 -0.684794 -0.214307 -1.133833
        1   True   0.603602  1.387020 -0.830780 -1.242000 -0.321938  0.484271  0.171738
            False -1.591730  1.282136  0.095159 -1.239882  0.760880 -0.606444 -0.485957
        2   True  -1.346883  1.650247 -1.476443  2.092067  1.344689  0.177083  0.100844
            False  0.001407 -1.127299 -0.417828  0.143595 -0.277838 -0.478262 -0.350906
  B     0   True   0.722781 -1.093182  0.237536  0.457614 -2.500885  0.338257  0.009128
            False  0.321022  0.419357  1.161140 -1.371035  1.093696  0.250517 -1.125612
        1   True   0.237441  1.739933  0.029653  0.327823 -0.384647  1.523628 -0.009053
            False -0.459148 -0.598577 -0.593486 -0.607447  1.478399  0.504028 -0.329555
        2   True  -0.583052 -0.986493 -0.057788 -0.639798  1.400311  0.076471 -0.212513
            False  0.896755  2.583520  1.520151  2.367336 -1.084994 -1.233548 -2.414215
  </code></pre>
  
  <p>I know how to extract the data corresponding to a given column.  E.g. for column <code>'VII'</code>:</p>
  
  <pre><code>In [20]: df['VII']
  Out[20]: 
  Alpha  Int  Bool 
  A      0    True     0.892865
              False   -1.133833
         1    True     0.171738
              False   -0.485957
         2    True     0.100844
              False   -0.350906
  B      0    True     0.009128
              False   -1.125612
         1    True    -0.009053
              False   -0.329555
         2    True    -0.212513
              False   -2.414215
  Name: VII
  </code></pre>
  
  <p>How do I extract the data matching the following sets of criteria:</p>
  
  <ol>
  <li><code>Alpha=='B'</code></li>
  <li><code>Alpha=='B'</code>, <code>Bool==False</code></li>
  <li><code>Alpha=='B'</code>, <code>Bool==False</code>, column <code>'I'</code></li>
  <li><code>Alpha=='B'</code>, <code>Bool==False</code>, columns <code>'I'</code> and <code>'III'</code></li>
  <li><code>Alpha=='B'</code>, <code>Bool==False</code>, columns <code>'I'</code>, <code>'III'</code>, and all columns from <code>'V'</code> onwards</li>
  <li><code>Int</code> is even</li>
  </ol>
  
  <p>(BTW, I did rtfm, more than once even, but I really find it incomprehensible.)</p>