词云图
作者:互联网
requirement
import wordcloud
import jieba
具体实现代码
data_review_body.to_csv('data_review_body.txt', sep='\t', index=False)
# 读txt文件
text = open('data_review_body.txt', 'r', encoding='utf-8').read()
# 把文字剪开
cut_text = jieba.cut(text)
# 以空格拼接起来
result = " ".join(cut_text)
# 生成词云
wordcloud = WordCloud(background_color='white', # 背景颜色
width=1000,
height=600,
max_font_size=50, # 字体大小
min_font_size=10,
# mask=plt.imread('old.jpg'), # 背景图片
max_words=1000).generate(result)
plt.figure(figsize=[12, 10])
plt.imshow(wordcloud)
plt.axis('off')
plt.show()
实现效果
添加背景
mask=plt.imread('old.jpg')
标签:body,plt,text,review,云图,cut,txt 来源: https://www.cnblogs.com/Lethus/p/15792125.html