dask 数据框 看起来像这样:
A B C D
1 foo xx this
1 foo xx belongs
1 foo xx together
4 bar xx blubb
我想按 A、B、C 列分组,并将 D 中的字符串连接起来,中间有一个空格,以获得
A B C D
1 foo xx this belongs together
4 bar xx blubb
我看到如何用 Pandas 做到这一点:
df_grouped = df.groupby(['A','B','C'])['D'].agg(' '.join).reset_index()
这如何通过 dask 实现?
最佳答案
ddf = ddf.groupby(['A','B','C'])['D'].apply(lambda row: ' '.join(row)).reset_index()
ddf.compute()
输出:
Out[75]:
A B C D
0 1 foo xx this belongs together
0 4 bar xx blubb
关于python - Groupby 多列和聚合与 dask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59105423/