熊猫如何在某些条件下正确进行分组
我在尝试在pandas中进行分组时遇到了问题,我的数据是这个表,直到“sum”系列,我想要的输出是某种分组依据,它为我提供了这些系列的结果:desired_clientgroup和DesiredGroup_out_sum/avg/max。 例如,数字“104,23”是客户组 1 的总和(我不知道如何生成该组 1 甚至其总和)。
df_index | client_items | 价格 数量 | 总和 | desired_clientgroup | DesiredGroup_output_sum | |
---|---|---|---|---|---|---|
1 | 1 | 10,9 | 2 | 21,8 | 1 | 104,23 |
2 | 2 | 8,5 | 5 | 42,5 | 1 | |
3 | 3 | 5,75 | 3 | 17,25 | 1 | |
4 | 4 | 2,88 | 1 | 2,88 | 1 | |
5 | 5 | 9,9 | 2 | 19,8 | 1 | |
6 | 1 | 2,2 | 4 | 8,8 | 2 | 32,92 |
7 | 2 | 3,55 | 3 | 10,65 | 2 | |
8 | 3 | 4,49 | 3 | 13,47 | 2 | |
9 | 1 | 8,2 | 2 | 16 ,4 | 3 | 44,79 |
10 | 2 | 9,19 | 2 | 18,38 | 3 | |
11 | 3 | 6,67 | 1 | 6,67 | 3 | |
12 | 4 | 3,34 | 1 | 3,34 | 3 | |
13 | 1 | 15,99 | 3 | 47,97 | 4 | 162,65 |
14 | 2 | 19,9 | 5 | 99,5 | 4 | |
15 | 3 | 7,59 | 2 | 15,18 | 4 |
对此有什么想法吗?
I had an issue when trying to group by in pandas, my data is this table until "sum" series, my desired output is some kind of group by that delivers me the results with these series: desired_clientgroup and DesiredGroup_out_sum/avg/max.
For example the number "104,23" is the sum over the clientgroup 1 (which I dont know how to generate this group 1 or even its sum).
df_index | client_items | price | qty | sum | desired_clientgroup | DesiredGroup_output_sum |
---|---|---|---|---|---|---|
1 | 1 | 10,9 | 2 | 21,8 | 1 | 104,23 |
2 | 2 | 8,5 | 5 | 42,5 | 1 | |
3 | 3 | 5,75 | 3 | 17,25 | 1 | |
4 | 4 | 2,88 | 1 | 2,88 | 1 | |
5 | 5 | 9,9 | 2 | 19,8 | 1 | |
6 | 1 | 2,2 | 4 | 8,8 | 2 | 32,92 |
7 | 2 | 3,55 | 3 | 10,65 | 2 | |
8 | 3 | 4,49 | 3 | 13,47 | 2 | |
9 | 1 | 8,2 | 2 | 16,4 | 3 | 44,79 |
10 | 2 | 9,19 | 2 | 18,38 | 3 | |
11 | 3 | 6,67 | 1 | 6,67 | 3 | |
12 | 4 | 3,34 | 1 | 3,34 | 3 | |
13 | 1 | 15,99 | 3 | 47,97 | 4 | 162,65 |
14 | 2 | 19,9 | 5 | 99,5 | 4 | |
15 | 3 | 7,59 | 2 | 15,18 | 4 |
Some thoughts over this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIUC,您可以使用:
输出:
IIUC, you could use:
Output: