我有
处理 | 辅助 | 日期 |
---|---|---|
23d34 | 0 | 3.10.2020//tr>|
23d4t | 1 | 1.2020年10月14日|
56z45 | 3 | 020年10月13日//tr>|
23d34 | 0 | 020年10月13日//tr>
如果要按Process
和Date
分组,请尝试:
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
您可以使用聚合函数:min
、max
、first
、last
:
df_new = df.astype({'Assists':'str'})
.groupby('Process',as_index=False)
.agg({'Assists':','.join,'Date':'min'}))