title: pandas: sorting and dropping rows from a grouped dataframe
body: <p>I have a dataframe:</p>
  
  <pre><code>import pandas as pd
  df = pd.read_csv('test.csv')
  
     brand  rating
  0      a      81
  1      a      83
  2      a      60
  3      a      45
  4      b      73
  5      b      55
  6      b      90
  7      c      60
  8      d      70
  9      e      75
  10     e      80
  11     e      85
  </code></pre>
  
  <p>So far, I have figured out how to group my dataframe by brand and calculate the mean and count per brand category:</p>
  
  <pre><code>groupeddf = df.groupby('brand', as_index=False).agg(['count', 'mean'])
  </code></pre>
  
  <p>which produces:</p>
  
  <pre><code>      rating           
         count       mean
  brand                  
  a          4  67.250000
  b          3  72.666667
  c          1  60.000000
  d          1  70.000000
  e          3  80.000000
  </code></pre>
  
  <p>Now, I would like to sort these results by the mean value and drop any brands for which there are less than three (so in this case, drop the rows for C and D).</p>
  
  <p>I was trying to sort by 'mean':</p>
  
  <pre><code>groupeddf.sort_values('mean')
  </code></pre>
  
  <p>but, I get a KeyError:'mean'</p>
  
  <p>So I looked at my columns:</p>
  
  <pre><code>groupeddf.columns
  </code></pre>
  
  <p>which gives:</p>
  
  <pre><code>MultiIndex(levels=[['rating'], ['count', 'mean']],
         labels=[[0, 0], [0, 1]])
  </code></pre>
  
  <p>And, now I'm not really sure what to do. All I want to do, is:</p>
  
  <ul>
  <li>group my original dataframe by brand</li>
  <li>calculate the mean and number of
  each brand </li>
  <li>sort by mean in descending order </li>
  <li>eliminate any data where
  the count &lt; 3</li>
  </ul>