单词云用于多个单词的表达式



我有一个excel文件,其中有一列包含一些字符串值。其中一些值不止是一个单词。例如,我有一个值为"0"的单元格;心理健康";。但当我创建单词cloud时,它将其分为两个单词。如果我想把每一列都作为一个观察,我该怎么办?

df = pd.read_csv(r"C:Users.......jj.csv", encoding='utf8')
df = df["Outcome"]
our_mask = np.array(Image.open("C:\Users\.....\baby.png"))
stopwords = set(STOPWORDS)
wc = WordCloud(background_color = "white", font_path='arial',
colormap='Reds', random_state=1,repeat=True,
collocations=False,
max_words = 150,
stopwords = stopwords,
mask = our_mask,
contour_width = 1,
contour_color = 'Gray').generate(str(df))
#Plotting
plt.imshow(wc, interpolation = 'bilinear')
plt.axis('off')
plt.show()

为了解决这个问题,我首先使用value_counts((函数来获取我的"名称";价值观然后我更改了代码如下。。。

d = dict(zip(df["Name"], df["frequencies"]))
wc = WordCloud(background_color = "white", font_path='arial',
colormap='prism', random_state=1,repeat=True,
collocations=False,
max_words = 2000,
stopwords = stopwords,
mask = our_mask,
contour_width = 1,
contour_color = 'red', width=1600, height=800).generate_from_frequencies(d)

最新更新