标签:excludes word 词云 words 中国 counts txt 名人
代码如下:
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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。