如何解决使用 Twitter API 分析频率项时,Python 代码检索空列表
当我对推文进行分析时,结果为空,如下所示 代码没有问题 但结果是一个空列表!
结果如下 []
import re
import operator
import json
from collections import Counter
from nltk.corpus import stopwords
from nltk import bigrams
import string
from collections import defaultdict
import sys
com = defaultdict(lambda: defaultdict(int))
fname = '/content/covid19.json'
with open(file,'r') as f:
count_all = Counter()
for line in f.readlines():
if line.startswith('{'):
tweet = json.loads(line)
terms_only = [term for term in preprocess(tweet['text']) if term not in stop and not term.startswith(('@','#'))]
count_all.update(terms_only)
print(count_all.most_common(5))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。