小编Jua*_*opo的帖子

创建 python 词云时如何对多词术语进行分组?

我正在尝试使用 python 从一系列成分中创建一个词云,其中一些成分的名称中包含多个单词。我希望词云将这些名称视为单个元素,但我不知道如何实现这一点。例如:

import wordcloud as w
import numpy as np
import matplotlib.pyplot as plt

ingredients = ['cabernet sauvignon', 'apple', 'black pepper',
             'rice', 'smoked salmon',
             'dried tomato', 'butter', 'mushroom', 'goat cheese']
frequencies = [55, 83, 33, 42, 19, 23, 5, 69, 1]

# Wordcloud asks for a string, and I have tried separating the terms with ',' and '~'

text = ''
for i, word in enumerate(ingredients):
    text = text + frequencies[i] * (word + ',') 

wordcloud = w.WordCloud(collocations = …
Run Code Online (Sandbox Code Playgroud)

python text visualization

3
推荐指数
1
解决办法
6172
查看次数

标签 统计

python ×1

text ×1

visualization ×1