我的 WordCloud 缺少单词末尾的字母 's'

My WordCloud is missing the letter 's' at the end of words

起初我以为问题出在我的数据上,是我在清理数据时犯了一个错误。但是我查了一下,不是这样的。

我正在使用此代码:

import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

allWords = ' '.join([twts for twts in df['full_text']])
wordCloud = WordCloud(collocations=True, width = 1000,
height=600, random_state = 21, max_font_size = 120).generate(allWords)

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

现在我的 wordcloud 显示了像“coronaviru”、“viru”、“crisi”这样的词。collocations=True 它显示了与“冠状病毒病例”、“冠状病毒大流行”等其他词相结合的完整词。 有谁知道如何解决这一问题? 就像我说的,我检查了数据,那里总是正确的完整单词。所以我想错误发生在wordcloud上。

我的数据是这样的:

    created_at                        id                full_text
0   Sat Aug 01 00:25:53 +0000 2020    28934685093219    life is hard with coronavirus
1   Sat Aug 01 00:25:53 +0000 2020    28934685093219    coronavirus sucks

你做错了什么,你的代码对我有用:

import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud

array = {'full_text': ['life is hard with coronavirus', 'coronavirus sucks']}
df = pd.DataFrame(array)

plt.style.use('fivethirtyeight')
allWords = ' '.join([twts for twts in df['full_text']])
wordCloud = WordCloud(collocations=True, width = 1000,
height=600, random_state = 21, max_font_size = 120).generate(allWords)

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

这是输出:

您需要更改 WordCloud 函数中的参数:normalize_plurals=False。 参考:https://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html

normalize_plurals: bool, default=True. Whether to remove trailing ‘s’ from words. If True and a word appears with and without a trailing ‘s’, the one with trailing ‘s’ is removed and its counts are added to the version without trailing ‘s’ – unless the word ends with ‘ss’. Ignored if using generate_from_frequencies.