title: Count and Sort with Pandas
body: <p>I have a dataframe for values form a file by which I have grouped by two columns, which return a count of the aggregation. Now I want to sort by the max count value, however I get the following error:</p>
  
  <blockquote>
    <p>KeyError: 'count'</p>
  </blockquote>
  
  <p>Looks the group by agg count column is some sort of index so not sure how to do this, I'm a beginner to Python and Panda.
  Here's the actual code, please let me know if you need more detail:</p>
  
  <pre><code>def answer_five():
      df = census_df#.set_index(['STNAME'])
      df = df[df['SUMLEV'] == 50]
      df = df[['STNAME','CTYNAME']].groupby(['STNAME']).agg(['count']).sort(['count'])
      #df.set_index(['count'])
      print(df.index)
      # get sorted count max item
      return df.head(5)
  </code></pre>