title: How to select conditional rows with groupby?
body: <p>I want to select rows with groupby conditions.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  dftest = pd.DataFrame({'A':['Feb',np.nan,'Air','Flow','Feb',
                              'Beta','Cat','Feb','Beta','Air'],
                         'B':['s','s','t','s','t','s','t','t','t','t'],
                         'C':[5,4,3,2,1,7,6,5,4,3],
                         'D':[4,np.nan,3,np.nan,2,
                              np.nan,2,3,np.nan,7]})
  def filcols3(df,dd):
      if df.iloc[0]['D']==dd:
          return df
  dd=4    
  grp=dftest.groupby('B').apply(filcols3,dd)
  </code></pre>
  
  <p>the result of grp is:</p>
  
  <pre><code>         A  B  C    D
  B                   
  s 0   Feb  s  5  4.0
    1   NaN  s  4  NaN
    3  Flow  s  2  NaN
    5  Beta  s  7  NaN
  </code></pre>
  
  <p>this is what I want.</p>
  
  <p>while if I use the following code(part 2)</p>
  
  <pre><code>def filcols3(df,dd):
      if df.iloc[0]['D']&lt;=dd:
          return df
  dd=3
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>       A    B    C    D
  0   NaN  NaN  NaN  NaN
  1   NaN  NaN  NaN  NaN
  2   Air    t  3.0  3.0
  3   NaN  NaN  NaN  NaN
  4   Feb    t  1.0  2.0
  5   NaN  NaN  NaN  NaN
  6   Cat    t  6.0  2.0
  7   Feb    t  5.0  3.0
  8  Beta    t  4.0  NaN
  9   Air    t  3.0  7.0
  </code></pre>
  
  <p>I'm surprise for this result, I mean to get</p>
  
  <pre><code>      A  B  C    D
  2   Air  t  3  3.0
  4   Feb  t  1  2.0
  6   Cat  t  6  2.0
  7   Feb  t  5  3.0
  8  Beta  t  4  NaN
  9   Air  t  3  7.0
  </code></pre>
  
  <p>what's wrong with the code of part 2? how to get the final result I want?</p>