【问题标题】:Error in an accepted answer: 'list' object is not callable接受的答案中有错误:\'list\' 对象不可调用
【发布时间】: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


【解决方案1】:

完全是我的错,对不起大家。我没有导入组合。

从 itertools 导入组合

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-01
    • 2012-04-21
    • 2014-06-13
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    相关资源
    最近更新 更多