【发布时间】:2020-08-27 16:14:56
【问题描述】:
我有以下数据框:
df:
S0 S1 V1 V2 V3 V4
A B 1 9 1 4
A B 2 8 1 4
A B 3 7 1 4
A B 4 6 1 4
A B 5 5 1 4
A B 6 4 1 4
A C 7 3 2 3
A C 8 2 2 3
A C 9 1 2 3
A C 9 0 2 3
我在这里做一个 groupby 来聚合值并得到下表:
df:
S0 S1 V1 V2 V3 V4
A B 21 39 1 4
A C 33 6 2 3
V1 和 V2 列按总和进行聚合,而 V3 和 V4 列根据 S1 列的唯一值取平均值。
如果直接使用 Groupby 聚合,则不会考虑列 S1 的唯一值。这方面的前进方向是什么?
【问题讨论】:
-
你能解释更多
Groupby aggregation if used directly does not consider the column S1 for unique values. What can be the way forward for this?吗?
标签: python pandas pandas-groupby