【发布时间】:2016-04-25 13:28:38
【问题描述】:
基于这个问题How to create a word cloud from a corpus in Python?,我使用amueller's 库构建了一个词云。但是,我看不到如何为云提供多个文本集。到目前为止,这是我尝试过的:
wc = WordCloud(background_color="white", max_words=2000, mask=alice_mask,
stopwords=STOPWORDS.add("said"))
wc.generate(set_of_words)
wc.generate("foo") # this overwrites the previous line of code
# but I would like this to be appended to the set of words
我找不到该库的任何手册,所以我不知道如何进行,是吗? :)
实际上,正如你在这里看到的:Dictionary with array of different types as value in Python,我有这个数据结构:
category = { "World news": [2, "foo bla content of", "content of 2nd article"],
"Politics": [1, "only 1 article here"],
...
}
我想将“foo bla content of”和“content of 2nd article”附加到世界云。
【问题讨论】:
-
为什么不将任何单词附加到原始集,然后生成扩展集?在某个点之后,它的计算成本会很高,但这是一个问题吗?
-
@NBartley 我有一本字典,其中每个键都有多个值,每个值都是多个单词。我想附加前 5 个键的所有单词,但我不知道该怎么做。我是 Python 新手。
-
您能否提供一些详细说明此问题的代码?目前尚不清楚您的
set_of_words是什么数据结构。 -
哦@NBartley 非常抱歉,我以为我有更新,请查看我更新的问题。
标签: python word-cloud