here is the dataframe I'm currently working on :
df_weight_0
What I'd like to calculate is the average of the variable "avg_lag" weighted by "tot_SKU" in each product_basket for both SMB and CORP groups. This means that, taking CORP as an example, I want to calculate something as:
(585,134 * 46.09 + 147,398 * 104.55 + ... + 1,112,941 * 75.73) / (585,134 + 147,398 + ... + 1,112,941)
and the same will need to be done for SMB.
Ideally, I'd like to have this two numbers in the dataframe above in a new column (SMB and CORP rows will have their weighted average repeated according to the two values calculated as shown above).
P.S. I will go deeper on more levels in my analysis so the most general the approach, the better.
Thanks in advance,
Stefano