title: How can I get the most popular item in a group in pandas?
body: <p>I have a Pandas Dataframe containing cars for sale and I'd like to get the most popular for each brand, however I seem unable to do this.</p>
  
  <p>I have a pandas dataframe with some columns (e.g: vehicle type, price, mileage, year, brand, model, etc) and for each car brand, I'd like to check which model occurs  the most.
  I've tried to use a groupby, like this: <br/></p>
  
  <pre><code>popular_models = dataset.groupby('brand').model.value_counts().groupby(level=0).nlargest(1)
  </code></pre>
  
  <p>But it returns a Pandas Series in which some of the data I want is stored in the indices and it also adds one repeated column that is not making any sense to me.</p>
  
  <p>I'd like to get a a DataFrame containing 3 columns, like this:<br/><br/>
  (<a href="https://imgur.com/a/BkKBrv9" rel="nofollow noreferrer">https://imgur.com/a/BkKBrv9</a>)</p>
  
  <p>However, I'm getting a pandas series like this:<br/><br/>
  (<a href="https://imgur.com/a/u8CSXY4" rel="nofollow noreferrer">https://imgur.com/a/u8CSXY4</a>)</p>
  
  <p>Can someone please help me figure this out?</p>