title: How can I iterate and apply a function over a single level of a DataFrame with MultiIndex?
body: <p>Thanks to the response to my <a href="https://stackoverflow.com/q/11037895/24895">initial question</a>, I now have a multi-indexed DataFrame the way that I want it.  Now that I have the data <em>in</em> the data structure, I'm trying to get it out and wonder if there is a better way to do this.  My two problems are related, but may have separate "ideal" solutions:</p>
  
  <p><strong>Sample DataFrame (truncated)</strong></p>
  
  <pre><code>Experiment           IWWGCW         IWWGDW       
  Lead Time                24     48      24     48
  2010-11-27 12:00:00   0.997  0.991   0.998  0.990
  2010-11-28 12:00:00   0.998  0.987   0.997  0.990
  2010-11-29 12:00:00   0.997  0.992   0.997  0.992
  2010-11-30 12:00:00   0.997  0.987   0.997  0.987
  2010-12-01 12:00:00   0.996  0.986   0.996  0.986
  </code></pre>
  
  <p><strong>Iteration</strong></p>
  
  <p>I'd like to be able to loop over this DataFrame where the iteration would take me down only 1 index dimension, i.e. an <code>iteritems</code> behavior that would return <code>[('IWWGCW', df['IWWGCW']), ('IWWGDW', df['IWWGDW'])]</code> and yield 2 DataFrames with Lead Time columns.  My brute-force solution is to use a wrapper routine that basically does <code>[(key, df[key] for key in df.columns.levels[0]]</code>.  Is there a better way to do this?</p>
  
  <p><strong>Apply</strong></p>
  
  <p>I'd also like to do things like "subtract the IWWGDW entries from everybody else" to compute paired differences.  I tried to do <code>df.apply(lambda f: f - df['IWWGDW'])</code> but get a <code>KeyError: ('IWWGDW', 'occurred at index 2010-11-26 12:00:00')</code> regardless of if I use <code>axis=1</code> or <code>axis=0</code>.  I've tried rebuilding a new DataFrame using the iteration workaround identified above, but I always worry when I brute-force things.  Is there a more "pandasic" way to do this sort of computation?</p>