【发布时间】:2022-12-14 08:42:32
【问题描述】:
在another topic,有这个问题我正在尝试解决。有一个非常详细的答案,由于某种原因对我不起作用并给出
TypeError: 'list' object is not callable
df=
index sale_id item
33337606 02234563 389699
29350189 02234520 230153
5002610 02234403 P79927
3357151 02235866 I25240
29351311 02234520 230155
... ... ...
grp = df.groupby('sale_id')['item'].agg(lambda x: ''.join(x))
purchases = grp.apply(lambda x: ''.join(x)).unique()
unique_items = df.item.unique()
res = {}
for c in combinations(unique_items, 2):
c = set(c)
res[frozenset(c)] = 0
for i in purchases:
if c.intersection(i) == c:
res[frozenset(c)] += 1
for k, v in res.items():
res[k] = v / purchases.shape[0]
res
【问题讨论】:
-
听起来您为不应该拥有的东西分配了一个列表,但我们无法从中分辨出来。发布 minimal reproducible example 和完整、准确的错误消息,包括完整的堆栈跟踪。
标签: python pandas dataframe error-handling