【发布时间】:2022-01-08 12:53:28
【问题描述】:
我有一张如下所示的表格:
平均行数和总行数的计算方式如下:
df1.loc["Average"] = df1.mean()
df1.loc["Total"] = df1.sum()
现在,我意识到这里的问题是平均计算正确,但总和也包括平均行,这不是我想要的。
理想情况下,我希望看到更像单个 .loc 行的东西,其中应用了 sum()
`columns` ['Enageable R', 'R Responses', 'R Response Rate', 'Engageable Q',
'Q Responses', 'Q Response Rate']
和mean() 应用于columns ['R Response Rate', 'Q Response Rate']
所以我很想看到这样的东西:
| 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% |
【问题讨论】:
-
我认为你的目标输出与你的描述不匹配
-
@ZLi 我试图绕过 sum() 计算总和中包含的 mean() ,我认为这是一个冲突。你能推荐一个不同的描述吗?
标签: python pandas dataframe sum mean