title: Pandas query after groupby and agg function
body: <p>I have the following piece of code already, basically I'm grouping by week and then by the tenant, then manupulating the data by calculating the p95 and p90, now I only want to print violators, as in when p90 is &gt;10 or p95 is &gt; 50. I tried using query after manupulating the data frame, it doesn't work as it complains about key error. Any way I can run my computations inside the agg function itself ? Below is the code I have come up with :</p>
  <pre><code>total_logs_percentiles = data.groupby(['version_week', 'tenant']).agg({'time_in_queue': {'p90': p90_agg, 'p95': p95_agg},
                                                                         'duration': {'p90': p90_agg, 'p95': p95_agg}})
  </code></pre>
  <p>This is an example data output from the above expression:</p>
  <pre><code>
                          time_in_queue  duration
                          p90      p95   p90  p95
  version_week tenant
  1            google      0.9     22   44    0.5
               yahoo       12      21   4     0.5
               bing        0.5     22   5     0.5
               duckduckgo  0.7     23   4     0.5
               IE          25      24   46    0.5
               Edge        60      25   47    0.5
  </code></pre>
  <p>Then I'm doing a query to filter the violators like below, but it doesn't work and complains with key error, how do I fix it ?</p>
  <pre><code>total_access_logs_percentiles.query('time_in_queue.p90 &gt; 10', engine='python')
  </code></pre>
  <p>How do I fix the above and also optimizze this in such way that I can filter the values out in the agg function itself ? p90_agg and p95_agg are functions I already have.</p>