How to make table in the first mission of The Weighted mean and median

Hi,

I would like to make the following table:
image

I wrote this code to group by year to get the Mean price per year. However, I am having trouble adding the Houses Sold column into the grouped dataframe. The Houses Sold column is the value_counts of the Years. How can I do this? Thank you in advance.

houses_year = houses[['Yr Sold','SalePrice']]
grouped_year = houses_year.groupby(['Yr Sold'])
grouped_sales_year = grouped_year['SalePrice']
houses_year = grouped_sales_year.mean()

Hey @ale_aleivaar,

Just add this line at the end,
houses_year = pd.concat([houses_year, houses[‘Yr Sold’].value_counts()], axis=1)

It will give you the table you want!!

2 Likes