Groupby of multiple Columns



我有

3.10.2020//tr>1.2020年10月14日020年10月13日//tr>020年10月13日//tr>
处理 辅助 日期
23d34 0
23d4t 1
56z45 3
23d34 0

如果要按ProcessDate分组,请尝试:

df_new = df.groupby(["Process", "Date"], as_index=False)["Assists"].apply(
lambda x: ",".join(x.astype(str))
)
print(df_new)

打印:

Process        Date Assists
0   23d34  13.10.2020     0,0
1   23d4t  14.10.2020       1
2   56z45  13.10.2020       3

您可以使用聚合函数:minmaxfirstlast:

df_new = df.astype({'Assists':'str'})
.groupby('Process',as_index=False)
.agg({'Assists':','.join,'Date':'min'}))

最新更新