title: Get the number of outliers by group in Pandas
body: <p>I'm trying to get the number of outliers by group from a Pandas data frame.</p>
  
  <p>My data looks like this.</p>
  
  <pre><code>df = pd.DataFrame({'group':list('aaaabbbb'),
                     'val':[1,3,3,2,5,6,6,2],
                     'id':[1,1,2,2,2,3,3,3],
                     'mydate':['01/01/2011 01:00:00',
                               '01/01/2011 01:02:00',
                               '01/01/2011 01:05:00',
                               '01/01/2011 01:06:00',
                               '01/01/2011 03:00:00',
                               '01/01/2011 04:00:00',
                               '01/01/2011 05:00:00',
                               '01/01/2011 10:00:00']})
  df
  </code></pre>
  
  <p>To get the number of outliers, I'm using the following function that gets the IQR.</p>
  
  <pre><code>def get_IQR():
      q1 = df["val"].quantile(0.25)
      q3 = df["val"].quantile(0.75)
      iqr = (df["val"] &gt; q1) &amp; (df["val"] &lt; q3)
      return val.loc[iqr]
  
  df[["group","val"]].agg([get_IQR])    
  </code></pre>
  
  <p>This doesn't work and produced the following results </p>
  
  <pre><code>ValueError: no results
  </code></pre>
  
  <p>Does anyone have a better strategy for finding the number of outliers per group, such that...</p>
  
  <pre><code>group   num_outliers
  a        ...
  b        ...
  c        ...
  </code></pre>