title: How to select top n row from each group after group by in pandas?
body: <p>I have a pandas dataframe with following shape</p>
  
  <pre><code> open_year, open_month, type, col1, col2, ....
  </code></pre>
  
  <p>I'd like to find the top type in each (year,month) so I first find the count of each type in each (year,month)</p>
  
  <pre><code>freq_df = df.groupby(['open_year','open_month','type']).size().reset_index()
  freq_df.columns = ['open_year','open_month','type','count']
  </code></pre>
  
  <p>Then I want to find the top n type based on their freq (e.g. count) for each (year_month). How can I do that?</p>
  
  <p>I can use <code>nlargest</code> but I'm missing the type</p>
  
  <pre><code>freq_df.groupby(['open_year','open_month'])['count'].nlargest(5)
  </code></pre>
  
  <p>but I'm missing the column <code>type</code></p>