简体   繁体   中英

How to count the numer of mentions of words from a column?

I'm trying to count how many times a word is mentioned in the column tokenized in the file reviews_english .

The column tokenized looks as follows {restaurant, Juni, 2019, Arrogante, service, ..} . With my current code I get the following error message

TypeError: unhashable type: 'set'

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

The column tokenized appears to be of type set . This is problematic not only because (as the error states) sets are not hashable, but also because sets do not contain duplicates, and so all of the words will appear in the set only once. If you're able to make tokenized into a list before it is populated, there can be duplicate values and therefore words can show up multiple times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM