繁体   English   中英

Python pandas groupby 在单元格中获取列表(excel)

[英]Python pandas groupby get list in the cell (excel)

所以我是 pandas excel 中的新手 python 这就是我想要实现的目标

之前的数据

我想要得到什么

我还没有找到使用 groupby 来执行此操作的具体方法请帮忙

你可以尝试groupby然后agg

df['c'] = df['c'].astype(str)

out = df.groupby(['a', 'b'])['c'].agg(','.join).reset_index()
print(out)

   a  b    c
0  1  2  3,4
1  1  3    5
2  2  2  3,4
3  2  3    5
4  5  6    7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM