如何将Groupby与原始DataFrame合并?
我有一个带有32列的数据框,类似的内容是:
company_id Price Date others columns
10 258.33 2021-08-01 ...
11 300.00 2022-01-01 ...
12 760.82 2021-11-01 ...
我想要公司和一个月的组:
df.groupby(['company_id', 'Date']).sum()
这很好,但是如何将输出与上面的初始数据框架合并?喜欢所有的行。会有双龙,但很好。
I have a dataframe with 32 columns, something like that :
company_id Price Date others columns
10 258.33 2021-08-01 ...
11 300.00 2022-01-01 ...
12 760.82 2021-11-01 ...
I want a groupby by company and by month :
df.groupby(['company_id', 'Date']).sum()
This works perfectly fine but how to merge the output with my initial dataframe above ? Like for all the rows. There will be doublons but it's fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IUUC,您想要的是Groupby,并转换
IUUC, what you want is groupby and transform