I have a dataset, df, that looks similar to this:
houses price
ranch 300,000
ranch 350,000
ranch 400,000
condo 250,000
condo 275,000
townhome 300,000
I would like to groupby the different categories within the 'houses' column and display the percentage of each category
Desired output
houses percent
ranch 50%
condo 33%
townhome 16.60%
This is what I am doing:
percent is part/whole
df1 = df.groupby['houses'].sum() #df1 gives us the sum
percent = df1.['houses']/df1
However, I am not retaining both columns houses and percent Any suggestion is appreciated