Home > Mobile >  Python Pandas Average and Sum conflicts
Python Pandas Average and Sum conflicts

Time:12-02

I have a table that looks like this:

table

The average and total rows are being calculated like so:

df1.loc["Average"] = df1.mean()
df1.loc["Total"] = df1.sum()

Now, I realized that the problem here is that the Average is calculating properly, but the sum is including the Average row as well, which is not what I want.

Ideally, I'd like to see something more like a single .loc row that has sum() applied to

`columns` ['Enageable R', 'R Responses', 'R Response Rate', 'Engageable Q',
                                'Q Responses', 'Q Response Rate']

and mean() applied to columns ['R Response Rate', 'Q Response Rate']

So I would love to see something like this:

Brand Engageable R R Responses Response Rate
Brand1 34 34 100.00%
Brand2 34 34 100.00%
Brand3 34 34 100.00%
Total 102 102 100.00%

CodePudding user response:

Use tablerevised

So the sum and average columns are not including each other in the calculations of the other rows.

  • Related