【问题标题】:word cloud counting double words instead of one词云计数双词而不是一个
【发布时间】:2022-01-26 16:11:35
【问题描述】:

我正在尝试在 python 中使用 matplotlib 做一个词云,而不是像“will”这样计算单个单词,而是像“i will”那样计算两个单词。我查看了 word cloud 文档,似乎没有任何东西会产生这种情况,我的输入会导致这种情况吗?

我的代码如下所示:

fields = ['comments']

text= pd.read_csv('comments.csv', usecols=fields)

stopwords = ["https", "RT"] + list(STOPWORDS)

print(' '.join(text['comments'].tolist()))

wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(' '.join(text['comments'].tolist()))

plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

【问题讨论】:

    标签: python dataframe matplotlib


    【解决方案1】:

    文档 (https://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html) 指出:

    搭配:bool,默认=True

    是否包含两个单词的搭配(二元组)。如果使用 generate_from_frequencies 则忽略。

    您可能需要在 WordCloud 的参数中包含 collocations=False。

    【讨论】:

    • 非常感谢,这就是问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 2022-11-08
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多