I am having a DataFrame with a bunch of companies, each company is assigned to one of five groups (ESG Bottom, ESG 4, ESG 3, ESG 2 or ESG Top).
Now I need to compute the weight of each company within its group in order to then compute their weighted group return and hence the overall group return.
I have managed to use groupby to get each groups summed market capital (MC)
and each companies individual MC.
My question is, how can I now divide the companies' individual MC by its respective total group MC and save the resulting weight in the "Weight in Quintile PF" column?
I could somehow manage to do this with a clumsy and slow for-loop but there must be a more elegant one (or two) liner which divides the inividual company MC with the respective total group MC.