简体   繁体   English

如何为 python 中的短语而不是单个单词创建 wordcloud

[英]How to create a wordcloud for a phrase not individual word in python

I'm trying to create wordcloud from a list that each name is a phrase but at final result each part shows separately and need to keep them as one element at wordcloud我正在尝试从每个名称都是一个短语的列表中创建 wordcloud,但最终结果是每个部分分别显示,并且需要将它们作为一个元素保留在 wordcloud

after I plot this data frame each part of the word placed separately at the picture.我把plot这个数据框的每一部分字分别放在图片上。 How to keep each value together?`如何将每个值保持在一起?

df=['Jurassic park','Captain America','Universal Studios','Mad max']

text=df
title = WordCloud(width=1000,             height=500,background_color="white",max_words=10).generate(text)
plt.axis("off")
plt.imshow(title)
plt.show()

` `

You can simply use a for loop to look through each item and do whatever you need to with the length of the words.您可以简单地使用 for 循环来查看每个项目,并根据单词的长度做任何您需要的事情。

df=['Jurassic park','Captain America','Universal Studios','Mad max']

for name in df:
    print(len(name))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM