运用python 中jieba完成

 

建议参考如下文档

建议参考如下文档

以前写的一段代码给你参考:

import jieba 
from wordcloud import WordCloud
import os,glob
import re
from collections import Counter
import matplotlib.pyplot as plt

stopwords = ['下回分解','第一','一个']
txt=[]
for f in [os.path.join(os.getcwd(),x) for x in glob.glob('F:/2021/answer5/红楼梦/*.txt')]:
    with open(f,'r',encoding='utf-8') as fr:
        txt.append(fr.read())
txt='\n'.join(txt)
word=[w for w in jieba.cut(txt) if w not in stopwords and w in re.findall('[\u4e00-\u9fff]+',txt) and len(w)>1]
c=Counter(word)
words=' '.join(c.keys())
wc = WordCloud(font_path='C:/Windows/Fonts/simsun.ttc',
               max_words=100).generate(words)
plt.imshow(wc, interpolation='bilinear')
plt.axis('off')
plt.show()

 

您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632