title: Slice pandas DataFrame by MultiIndex level or sublevel
body: <p>Inspired by <a href="https://stackoverflow.com/a/14964637/2071807">this answer</a> and the lack of an easy answer to <a href="https://stackoverflow.com/questions/12224778/how-to-filter-by-sub-level-index-in-pandas">this question</a> I found myself writing a little syntactic sugar to make life easier to filter by MultiIndex level.</p>
  
  <pre><code>def _filter_series(x, level_name, filter_by):
      """
      Filter a pd.Series or pd.DataFrame x by `filter_by` on the MultiIndex level
      `level_name`
  
      Uses `pd.Index.get_level_values()` in the background. `filter_by` is either
      a string or an iterable.
      """
      if isinstance(x, pd.Series) or isinstance(x, pd.DataFrame):
          if type(filter_by) is str:
              filter_by = [filter_by]
  
          index = x.index.get_level_values(level_name).isin(filter_by)
          return x[index]
      else:
          print "Not a pandas object"
  </code></pre>
  
  <p>But if I know the pandas development team (and I'm starting to, slowly!) there's already a nice way to do this, and I just don't know what it is yet!</p>
  
  <p>Am I right?</p>