autos['brand'].value_counts(normalize=True).mul(100).head(10)
volkswagen 21.091133
bmw 11.118456
opel 10.880487
mercedes_benz 9.371144
audi 8.798255
ford 6.998061
renault 4.814472
peugeot 3.067160
fiat 2.564781
seat 1.877314
Name: brand, dtype: float64
brands_10 = ['volkswagen', 'bmw', 'opel', 'mercedes_benz', 'audi', 'ford', 'renault', 'peugeot', 'fiat', 'seat']
avg_cost_10brands = {}
for each_brand in brands_10:
brand_price = autos.loc[autos["brand"] == each_brand, ["brand", "dollar_price"]]
avg_cost_10brands[each_brand] = round(brand_price["dollar_price"].mean())
avg_cost_10brands
{'volkswagen': 5399,
'bmw': 8361,
'opel': 2954,
'mercedes_benz': 8582,
'audi': 9420,
'ford': 3448,
'renault': 2420,
'peugeot': 3088,
'fiat': 2705,
'seat': 4402}
so i have a “percent of sales per brand” and an “average sale value per brand” i want to make one dictionary to display both. not sure how to go about it.
edit;
altered first cell
brand_sales = autos['brand'].value_counts(normalize=True).mul(100).head(10)
brand_sales
and shortened the code to one line and started trying pd.concat and pd.append. they didn’t work how i’ve used them.
brands_10 = ['volkswagen', 'bmw', 'opel', 'mercedes_benz', 'audi', 'ford', 'renault', 'peugeot', 'fiat', 'seat']
avg_cost_10brands = {}
for each_brand in brands_10:
avg_cost_10brands[each_brand] = round(autos.loc[autos["brand"] == each_brand, ["brand", "dollar_price"]]["dollar_price"].mean())
# avg_cost_10brands
pd.append([brand_sales, avg_cost_10brands])