中英文分词后进行词频统计(包含词云制作)


 在之前的分词学习后,开始处理提取的词语进行词频统计,因为依据词频是进行关键词提取的最简单方法:

1、英文词频统计和词云制作

 词云,又称文字云、标签云,是对文本数据中出现频率较高的“关键词”在视觉上的突出呈现,形成关键词的渲染形成类似云一样的彩色图片,从而一眼就可以领略文本数据的主要表达意思。

from nltk import word_tokenize  #分词处理
from nltk.corpus import stopwords  #停用词
from nltk import FreqDist    #统计词频
from wordcloud import WordCloud   #词云
from imageio import imread   #导入图片进行处理
import matplotlib.pyplot as plt  # 利用Python的Matplotlib包进行绘图

paragraph = 'Water has the property of dissolving sugar and sugar has the property being dissolved by water.'.lower()
cutwords1 =  word_tokenize(paragraph)
print('【原句子为:】'+ '\n'+ paragraph)
print('\n【NLTK分词结果:】')
print(cutwords1)

interpunctuations = [',', '.', ':', ';', '?', '(', ')', '[', ']', '&', '!', '*', '@', '#', '$', '%']   #定义符号列表
cutwords2 = [word for word in cutwords1 if word not in interpunctuations]   #去除标点符号
print('\n【NLTK分词后去除符号结果:】')
print(cutwords2)

stops = set(stopwords.words("english"))
words_lists = [word for word in cutwords2 if word not in stops]  #判断分词在不在停用词列表内
print('\n【NLTK分词后去除停用词结果:】')
  • 12
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值