【问题标题】:How to count the numer of mentions of words from a column?如何计算列中单词的提及次数?
【发布时间】:2021-06-04 11:40:21
【问题描述】:

我正在尝试计算文件reviews_english 中的tokenized 列中某个单词被提及的次数。

tokenized 列如下所示{restaurant, Juni, 2019, Arrogante, service, ..}。使用我当前的代码,我收到以下错误消息

TypeError: unhashable type: 'set'

import collections
from collections import Counter
counts = collections.Counter(reviews_english['tokenized']) 

【问题讨论】:

    标签: python counter sentiment-analysis review


    【解决方案1】:

    tokenized 列的类型似乎是 set。这是有问题的,不仅因为(如错误状态)集合不可散列,还因为集合不包含重复项,因此所有单词在集合中只会出现一次。如果您能够将tokenized 放入列表填充它之前,可能会有重复的值,因此单词可能会出现多次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2013-12-25
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多