【发布时间】:2021-06-21 09:40:03
【问题描述】:
我有一张这样的桌子:
col1 col2
a {...}
a {...}
b {...}
c {...}
c {...}
c {...}
col2 由集合组成。我需要按col1 聚合,这样col2 是集合的并集。
到目前为止我最好的尝试是这样的:
def set_union(*sets):
return reduce(lambda a, b: a.union(b), sets)
mytable.groupby('col1', as_index=False)['equivalente_new'].agg(set_union)
产量:
ValueError: 必须产生聚合值
有人有解决办法吗?
【问题讨论】:
标签: python pandas set pandas-groupby aggregate