title: Counting rows under multindex dataframe pandas
body: <p>I have the following dataframe indexed as follows:</p>
  
  <pre><code>census_df = pd.read_csv('census.csv')
  columns_to_keep=['STATE','COUNTY','STNAME','CTYNAME']
  census_df=census_df[census_df['SUMLEV']==50]
  df=census_df[columns_to_keep]
  df = df.set_index(['STNAME','CTYNAME'])
  df.head()
  </code></pre>
  
  <p>And looks like this </p>
  
  <p><a href="https://i.stack.imgur.com/EP5gU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EP5gU.png" alt="enter image description here"></a></p>
  
  <p>Where "STNAME" is the state name and "CITYNAME" is the county name. Every state and county have a specific code as show in the columns "STATE" and "COUNTY". </p>
  
  <p>I need to return the name of the state with the maximum counties. So far I have done something like this</p>
  
  <pre><code>df.groupby('STATE').count()
  num_state= g['COUNTY'].argmax()
  state_name = df[df['STATE']==num_state].index[0][0]
  </code></pre>
  
  <p>But I am sure there must be an easier way to count through rows in multindex dataframe. </p>
  
  <p>Thanks</p>