Exploring Price by brand: My top 6 is a little different than the DQ's solution

As you can see my top 6 brands are a little different than the ones provided in the next mission. If you look at my output, I have ‘sonstige_autos’, ‘mini’ and ‘skoda’ in the top 6. Can you please explain what I did wrong? Thanks

Screen Link: https://app.dataquest.io/m/294/guided-project%3A-exploring-ebay-car-sales-data/7/exploring-price-by-brand

My Code:

top_brand = autos['brand'].value_counts().sort_values(ascending=False).head(20).index
brand_mean_price = {}
for value in top_brand:
    brand_row = autos[autos['brand'] == value]
    mean = brand_row['price_$'].mean()
    brand_mean_price[value] = int(mean)
#sorting the brand_mean_price
sorted_mean = sorted(brand_mean_price.items(), key=lambda x: x[1], reverse=True)
for i in sorted_mean:
    print(i[0],':',i[1])

What I expected to happen:

audi             9336
bmw              8332
ford             3749
mercedes_benz    8628
opel             2975
volkswagen       5402
dtype: int64

What actually happened:

sonstige_autos : 12365
mini : 10613
audi : 9336
mercedes_benz : 8628
bmw : 8332
skoda : 6368
volkswagen : 5402
hyundai : 5365
toyota : 5167
volvo : 4946
nissan : 4743
seat : 4397
mazda : 4112
citroen : 3779
ford : 3749
smart : 3580
peugeot : 3094
opel : 2976
fiat : 2813

Hi @nelsonlupanda . It has to do with how you defined a “top brand”. If you look at the breakdown of the brands (autos['brand'].value_counts(normalize=True)), it shows you how popular each brand is on the site. sonstige_autos and mini may have the highest mean prices, but they only make up less than 1% of the available cars each. The official solution focused only on cars that make up at least 5% of the total values, which is why they have a smaller list.

I hope that makes sense!

Hi @april.g If I understand correctly, my approach is not wrong, it’s just different than DataQuest’s. if so, how do I select brands that make up 5% or more of the cars available?
Thanks taking the time to respond.

Hey @april.g never mind. I was able to figure it out. Thanks again

Yep, you got it. Glad you were able to get the other part figured out on your own. Happy learning!