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.
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:
popular_models = dataset.groupby('brand').model.value_counts().groupby(level=0).nlargest(1)
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.
I'd like to get a a DataFrame containing 3 columns, like this:
(https://imgur.com/a/BkKBrv9)
However, I'm getting a pandas series like this:
(https://imgur.com/a/u8CSXY4)
Can someone please help me figure this out?