title: Loop through grouped data - Python/Pandas
body: <p>I'm trying to perform an action on grouped data in Pandas. For each group, I want to loop through the rows and compare them to the first row in the group. If conditions are met, then I want to print out the row details. My data looks like this:</p>
  
  <pre><code>Orig  Dest  Route  Vol    Per   VolPct
  ORD   ICN   A      2,251  0.64  0.78
  ORD   ICN   B      366    0.97  0.13
  ORD   ICN   C      142    0.14  0.05
  DCA   FRA   A      9,059  0.71  0.85
  DCA   FRA   B      1,348  0.92  0.13
  DCA   FRA   C      281    0.8   0.03
  </code></pre>
  
  <p>My groups are <code>Orig</code>, <code>Dest</code> pairs. If a row in the group other than the first row has a <code>Per</code> greater than the first row and a <code>VolPct</code> greater than .1, I want to output the grouped pair and the route. In this example, the output would be:</p>
  
  <pre><code>ORD ICN B
  DCA FRA B
  </code></pre>
  
  <p>My attempted code is as follows:</p>
  
  <pre><code>for lane in otp.groupby(otp['Orig','Dest']):
      X = lane.first(['Per'])
      for row in lane:
          if (row['Per'] &gt; X and row['VolPct'] &gt; .1):
              print(row['Orig','Dest','Route'])
  </code></pre>
  
  <p>However, this isn't working so I'm obviously not doing something right. I'm also not sure how to tell Python to ignore the first row when in the "row in lane" loop. Any ideas? Thanks!</p>