中国名人榜词云
作者:互联网
代码如下:
1)词频统计代码:
import jieba
from wordcloud import WordCloud
excludes={'演员','模特','21','200','20','700',\
'前十','10','职业','050','运动员','收入','歌手',\
'综合排名','姓名','11','600','导演','300','榜单','13',\
'16','900','800','万元','500','14','排名','12','000','17'}
f=open('mingrendangan.txt','r',encoding='utf-8')
txt=f.read()
words=jieba.lcut(txt)
counts={}
for word in words:
if len(word)==1:
continue
else:
counts[word]=counts.get(word,0)+1
for word in excludes:
del(counts[word])
items=list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
word,count=items[i]
print('{0:<10}{1:>5}'.format(word,count))
2)词云代码:
import jieba
from wordcloud import WordCloud
excludes={'演员','模特','21','200','20','700',\
'前十','10','职业','050','运动员','收入','歌手',\
'综合排名','姓名','11','600','导演','300','榜单','13',\
'16','900','800','万元','500','14','排名','12','000','17'}
f=open('mingrendangan.txt','r',encoding='utf-8')
txt=f.read()
f.close()
words=jieba.lcut(txt)
newtxt=''.join(words)
wordcloud=WordCloud(background_color='white',\
width=800,\
height=600,\
font_path='msyh.ttc',\
stopwords=excludes,\
).generate(newtxt)
wordcloud.to_file('名人词云.png')
词频统计截图:
词云截图:
中国名人榜词云展示:
主要问题:
① 第三方库安装不成功
② 打开网上下载的文本不成功
③ 找不到提交作业的地方
解决方法:
① 运用cmd指令更新版本,去网上下载visual c++ 14.0
② 是因为网上下载的文档里有无法读入的字符,从网上复制粘贴素材制作文本
③ 问教员,细心耐心
标签:excludes,word,词云,words,中国,counts,txt,名人 来源: https://www.cnblogs.com/i3i4/p/14675091.html