Average brand price does not match

Screen Link:

My Code:

brands = autos["brand"].value_counts().index
agg_counts = {}
for b in brands:
    selected_rows = autos[autos["brand"] == b]
    b_mean = selected_rows["price"].mean()
    agg_counts[b] = b_mean 

What I expected to happen:

The average price does not match with the average prices from the next lesson. I am wondering where I went wrong with my code above.

Here are the average prices from the next page:
audi 9336
bmw 8332
ford 3749
mercedes_benz 8628
opel 2975
volkswagen 5402

What actually happened:

{'jaguar': 11525.554054054053, 'skoda': 6353.544871794872, 'subaru': 3940.470588235294, 'toyota': 5148.0032733224225, ....}

Here are my averages:
'audi': 9212.9306621881
'bmw': 8260.768253366205
'ford': 3716.6291802308374
'mercedes_benz': 8523.472030981067
'opel': 2942.40447732878
'volkswagen': 5329.65634

Hi @jonathanmarcotte, welcome to the community!

It’s hard to say what’s causing the difference just from this snippet of code. The averages are pretty close, so my best guess is that you made some different choices in a previous section (like which rows were deleted or kept in the dataframe, for example). If you like I can have a look at it if you attach your .ipynb file.

Hi @april.g,

Thank you for taking the time to respond. Based off your feedback I realized the difference is most likely related to how I removed the outliers.

Thank you for your help and time!

1 Like

and here is mine:
{‘audi’: 9371.45305514158,
‘bmw’: 8369.67455505574,
‘citroen’: 3784.924961715161,
‘fiat’: 2818.456066945607,
‘ford’: 3755.9139256071317,
‘hyundai’: 5376.740899357602,
‘mazda’: 4112.596614950635,
‘mercedes_benz’: 8661.1348640214,
‘nissan’: 4750.063202247191,
‘opel’: 2995.3961507618283,
‘peugeot’: 3100.6928057553955,
‘renault’: 2484.749087591241,
‘seat’: 4417.942285041225,
‘skoda’: 6393.018348623853,
‘smart’: 3591.0212443095597,
‘toyota’: 5167.091062394604,
‘volkswagen’: 5420.53840675552}


here is mine