jieba库分词并生成词云

import jieba
import wordcloud

stop_words={}
with open('D:/res/stopwords.txt','r',encoding='utf-8') as f:
    stop_words=f.read()
stop_words=stop_words.split('\n')
text=[]
with open('D:/res/info.txt','r',encoding='utf-8') as f:

    text=jieba.cut(f.read())

w=wordcloud.WordCloud(font_path='C:/Windows/Fonts/simsun',stopwords=stop_words,scale=32)

w.generate(' '.join(text))
w.to_file('D:/res/pic.jpg')

将停用词文件和数据导入,对数据进行分词后,使用wordcloud去除停用词,加载中文字体,设置清晰度,得到词云。

注意如果有一些无意义词汇占比太大,可手动在stopword文件中添加停用词

你可能感兴趣的:(Python,python)