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')