Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从CSV文件中的列在Python中创建word cloud_Python_Csv_Word Cloud - Fatal编程技术网

从CSV文件中的列在Python中创建word cloud

从CSV文件中的列在Python中创建word cloud,python,csv,word-cloud,Python,Csv,Word Cloud,我正在尝试使用python从csv文件中的列创建word cloud。我已经安装了wordcloud、PIL、OS和Numpy,但我不知道如何阅读这一列来创建wordcloud。有人能帮忙吗?谢谢 这里是修改后的示例 我有一个'words.csv文件,在第一列中有单词(在下图中选择并显示),在下一列中有它们的解释 我们阅读csv文件(words)的第一列,然后运行word\u cloud import csv from wordcloud import WordCloud #read fir

我正在尝试使用python从csv文件中的列创建word cloud。我已经安装了wordcloud、PIL、OS和Numpy,但我不知道如何阅读这一列来创建wordcloud。有人能帮忙吗?谢谢

这里是修改后的示例

我有一个
'words.csv
文件,在第一列中有单词(在下图中选择并显示),在下一列中有它们的解释

我们阅读
csv
文件(words)的第一列,然后运行
word\u cloud

import csv
from wordcloud import WordCloud


#read first column of csv file to string of words seperated
#by tab

your_list = []
with open('words.csv', 'rb') as f:
    reader = csv.reader(f)
    your_list = '\t'.join([i[0] for i in reader])


# Generate a word cloud image
wordcloud = WordCloud().generate(your_list)

# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")

# lower max_font_size
wordcloud = WordCloud(max_font_size=40).generate(your_list)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()

# The pil way (if you don't have matplotlib)
# image = wordcloud.to_image()
# image.show()
图像

欢迎来到SO,请澄清您的问题,展示您已经尝试过的内容以及您得到的输出/错误,我们可以尝试帮助您解决这个问题,因为它太宽泛,只会吸引基于意见的答案(因此希望它关闭)。请转到:,然后读:和:。