我正在尝试使用textblob分析twitter数据。我的twitter文本中最常用的bigram及其各自的频率被检索并存储在列表变量“l”中,如下所示
from textblob import TextBlob
blob = TextBlob(text)
import nltk, re, string, collections
from nltk.util import ngrams
'first get individual words'
tokenized = blob.split()
'and get a list of all the bi-grams'
Bigrams = ngrams(tokenized, 2)
Bigrams
'get the frequency of each bigram '
BigramFreq = collections.Counter(Bigrams)
BigramFreq
' what are the ten most popular bigrams '
l = BigramFreq.most_common(10)
l
在这里,“l”的输出是一个列表,其中包含在运行上述代码后显示的每个双RAM的双RAM和频率,如下所示:
[(('@UniverCurious:', 'The'), 39),
(('The', 'underside'), 38),
(('underside', 'of'), 38),
(('of', 'Jupiter.'), 38),
(('Jupiter.', 'Credit:'), 38),
(('Credit:', 'NASA/JPL/JUNO'), 38),
(('to', 'the'), 25),
(('just', '100'), 15),
(('20', 'years'), 14)]
现在我可以从最常见的bigram创建一个表。但是我需要帮助从上面给定的代码创建wordcloud
我的问题是如何从列表“l”创建wordcloud
谢谢!表创建现在可以正常工作了。 现在我扩展了创建wordcloud的代码,但它给出了一个错误“TypeError:expected string”。我扩展的代码如下所示:
错误如下所示:
如果我在这里做错了什么,请告诉我
这个怎么样?对于wordcloud,您可能需要使用其他模块,如
wordcloud
。有关示例,请参见this link相关问题 更多 >
编程相关推荐