title: Sort grouped by dataframe according to the count values of groups
body: <p>I have grouped by and sorted the values within group of dataframe by applying below 2 queries:</p>
  
  <pre><code>df = df.groupby(['table_name','query_param_clean2']).size().to_frame('count').reset_index()
  
  df = df.sort_values(['table_name','count'],ascending=False).groupby('table_name').apply(lambda x: x)
  </code></pre>
  
  <p>The dataframe looks like this now :</p>
  
  <pre><code>table_name           query_param_clean2           count
  A                       query4                    24
  A                       query1                    16
  A                       query2                    8
  B                       query5                    56
  B                       query6                    50
  C                       query3                    100
  D                       query1                    13
  D                       query4                    12
  D                       query2                    10
  D                       query8                    1
  </code></pre>
  
  <p>Here, I have dataframe properly grouped up and sorted according to the count with in the group. Now, I want to do the sorting between groups.</p>
  
  <p>For example: C under table_name has first row with highest value of 100, so C should be the top group in the output, after C , B should be there because the first row of B has the second largest value of 56 after 100.</p>
  
  <p>The output dataframe should look like below.</p>
  
  <p>What can i add in my second line of code or add something else to get data in below form.</p>
  
  <pre><code>table_name           query_param_clean2           count
  C                       query3                    100
  B                       query5                    56
  B                       query6                    50
  A                       query4                    24
  A                       query1                    16
  A                       query2                    8
  D                       query1                    13
  D                       query4                    12
  D                       query2                    10
  D                       query8                    1
  </code></pre>
  
  <p>Please suggest.</p>