python——jieba

import jieba
import jieba.analyse
from stylecloud import gen_stylecloud
# 1.读取要分析的文章
with open("ox.txt","r",encoding="utf-8") as f1:
txt=f1.read()
print(txt)
#2.进行分词 cut lcut
list1=jieba.lcut(txt)
print(list1)
# 3.去除停用词
with open("stopw.txt","r",encoding="utf-8") as f2:
stop_txt=f2.readlines() #读取一个列表
stopwords=[] #停用词列表
for i in stop_txt:
stopwords.append(i.strip('\n'))
good=[]
for a in list1:
if a not in stopwords and a!='\n' :
good.append(a)
print(len(good))
print(len(list1))

str1="".join(good)
print(str1)
#4.提取关键词 jieba.analyse.textrank(第一个参数是字符串 提取多少个关键词),整个方法返回的是一个列表
keylist=jieba.analyse.textrank(str1,topK=10)
print(keylist)
str2=" ".join(keylist)
#5.生成词云,gen_stylecloud(第一个参数字符串,中间是空格的字符串)
gen_stylecloud(str2,
icon_name='fas fa-globe', #词云的样式,前面fas fa-这是固定的
background_color='white', #背景颜色
output_name='66.jpg', #要生成图片的名称
font_path='msyh.ttc') 






 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

&forget&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值