Guided Project: Exploring Ebay Car Sales Data step 7.5

taking some stuff about concatenating series with dictionary i wanted to concatenate the percentage info and average price info from step 7

perc_frame = pd.DataFrame(brand_sales,columns = ['percentage'])
avg_price_frame = pd.DataFrame.from_dict(avg_cost_10brands, orient = 'index', columns = ['average_price'])

the perc_frame is empty, and i don’t know why.

brand_sales = autos['brand'].value_counts(normalize=True).mul(100).head(10)

that’s where i get the percentages from, and brand_sales is a series.

Top 10 brands, and how much their sales made up the total sales:
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

so pd.DataFrame should convert to a dataframe, and from there i should be able to just use pd.concat to combine them, but it doesn’t work because perc_frame is empty.

Hi @westlundderek
The brand_sales series is taking default name from the “brand” column from the “autos” dataset. So the column name “percentage” is not recognized by “pd.DataFrame” command.

Thanks for your question. It made me realize, I need to start paying attention to the bold part of the output:

seat 1.877314
Name: brand, dtype: float64

so, try either of the following statements and see the results:

perc_frame1 = pd.DataFrame(brand_sales) #,columns = ['percentage'])

perc_frame2 = pd.DataFrame(brand_sales, columns = ['brand'])

(Apologies, if my answer above did not make sense at all!) I hope, the code helps you to understand better.


this did indeed solve the empty frame problem, now i just need to learn how concat works.

1 Like