I want to calculate the relative percentages of a sum of a particular column of a dataframe after I have grouped by a different column. The format of the data frame would be for example:
df = pd.DataFrame({'Company': ['Company1', 'Company2', 'Company3', 'Company1', 'Company3'],
'STC Watts': [10.10, 9.6, 13.3, 5.6, 10.12],
...other columns
)
At this point I need to group by the "Company" columns and get the total sum of "STC Watts" column for each company, but I would also like to have a relative percentage of that company "STC Watts" sum out of the total for the entire dataset. I tried using a couple solutions from this question but could not get any of them to work