I have a large dataset with different rows that I created using formulas and the grouped by
function
# Create new column "iCPI"
grouped_sums['iCPI'] = grouped_sums['Budget Delivered'] / grouped_sums['Incr Conversions']
# Create new column "iCVR"
grouped_sums['iCVR%'] = (grouped_sums['Incr Conversions'] / grouped_sums['Clicks']) * 100
# Create new column "CPC"
grouped_sums['CPC'] = grouped_sums['Budget Delivered'] / grouped_sums['Clicks']
# Create new column "CPM"
grouped_sums['CPM'] = (grouped_sums['Budget Delivered'] / grouped_sums['Impressions']) * 1000
I created a column named Total
using this code
grouped_sums.loc['Total'] = grouped_sums.sum()
however this just takes the total sum of all the columns rather than taking into account the formulas I created up above. I need the total for each of the new columns to reflect the formula of the totals (ie. for iCPI
, it needs to be the sum of budget delivered
/ sum of Incr Conversions
My problem is the output as I do have the columns showing iCPI and other metrics. However, for the total output, the iCPI is only taking the sum of all iCPI values. Here is what it looks like for me: