title: Sort values within dataframe grouped by multiple columns
body: <p>I have a dataframe that is in this form.</p>
  
  <pre><code> Type  Major   GPA   
    F      A     2.6   
    T      B     3.4   
    T      C     2.9   
    F      A     1.8   
    T      B     2.8   
    F      C     3.5 
   ...
  </code></pre>
  
  <p>I'd like to group the Dataframe ("students") by <code>Type</code> and <code>Major</code>, count the number of rows for each grouping, then sort from most to least popular majors for each type, and, finally, create a new dataframe that includes the 20 most popular majors.</p>
  
  <p>I'd like the output to look like this:</p>
  
  <pre><code>F   
  A 21  
  B 19  
  C 15
  ...
  T  
  A 14  
  B 7  
  C 3   
  </code></pre>
  
  <p>This is what I did:</p>
  
  <pre><code>most_popular = students.groupby(['Type', 'Major']).size().sort_values(ascending=False)[:20]
  </code></pre>
  
  <p>But what this does is sort across both Types - rather than sort separately for each.</p>
  
  <p>Thank you for your help.</p>