当前位置: 首页 > news >正文

手机网站上线左右滑动郑州网站推广排名公司

手机网站上线左右滑动,郑州网站推广排名公司,江门网站设计华企立方,献县建设局网站-------------词云图集合------------- WordCloud去掉停用词(fit_wordsgenerate)的2种用法 通过词频来绘制词云图(jiebaWordCloud) Python教程95:去掉停用词词频统计jieba.tokenize示例用法 将进酒—李白process_t…

-------------词云图集合-------------

WordCloud去掉停用词(fit_words+generate)的2种用法

通过词频来绘制词云图(jieba+WordCloud)

Python教程95:去掉停用词+词频统计+jieba.tokenize示例用法

将进酒—李白process_text词频统计,及词频可视化分析

使用wordcloud模块,绘制一个自定义的词云图形状

使用WordCloud模块中repeat参数,做一个关键字重复的词云图

关于词云图显示异常,出现乱码的解决办法

盘点WordCloud模块,词云图的相关知识点

Python源码05:使用Pyecharts画词云图图

在WordCloud中去掉停用词,可以通过设置stopwords参数来实现,也可以通过下面字典数据的过滤方法来去掉不想要的词语。停用词是指在文本中频繁出现但对文本含义贡献很小的词语,如虚词、助词、介词、连词等。下面写的2个例子,可以给大家参考一下。

1.W.generate通常结合stopwords过滤停用词的方法,运行代码就会生成如下图。可以看到原文本(杨过是欧阳锋的义子,他的黯然销魂掌,可以和郭靖的降龙十八掌媲美),文本里面的 是,和,的,它等需要都被去掉了。
在这里插入图片描述

# -*- coding: utf-8 -*-
# @Author : 小红牛
# 微信公众号:WdPython
import jieba
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt# 1.读取文本
text = '杨过是欧阳锋的义子,他的黯然销魂掌,可以和郭靖的降龙十八掌媲美。'
print('1.原文本:'.center(50, '-'))
print(text)
# 2.分词
cut_word = jieba.cut(text, cut_all=False)
cut_word = ' '.join(cut_word)
print('2.jieba分词后的内容:'.center(50, '-'))
print(cut_word)
# 3.准备停用词表
stopwords = set(STOPWORDS)
print('3.WordCloud自带的英文停用词表:'.center(50, '-'))
print(stopwords)
# 自定义添加停用词
stopwords.add('是')
stopwords.add('的')
stopwords.add('和')
stopwords.add('他')
stopwords.add('可以')# 4.创建WordCloud对象并生成词云,stopwords=stopwords,
w = WordCloud(background_color='WHITE', stopwords=stopwords, height=400,width=700, font_path='simkai.ttf')w.generate(cut_word)
# 5.保存词云图图片
w.to_file('cloud.png')
# 显示词云图
plt.imshow(w)
plt.axis('off')
plt.show()
print('词云图生成完成。')

输出内容:

----------------------1.原文本:----------------------
杨过是欧阳锋的义子,他的黯然销魂掌,可以和郭靖的降龙十八掌媲美。
------------------2.jieba分词后的内容:------------------
杨过 是 欧阳锋 的 义子 , 他 的 黯然销魂 掌 , 可以 和 郭靖 的 降龙十八掌 媲美 。
--------------3.WordCloud自带的英文停用词表:---------------
{"you'll", "doesn't", 'yourself', 'after', 'by', "we're", 'other', 'and', 'just', 'this', "when's", 'hence', 'own', 'ours', 'myself', "won't", 'otherwise', 'what', 'on', 'can', 'else', "we'll", 'k', 'him', "haven't", "they'll", "she's", "i'd", 'there', 'itself', 'of', "you've", "there's", 'herself', 'off', 'his', 'once', "that's", 'very', 'was', 'ever', 'would', 'until', 'why', 'me', 'had', "where's", 'does', 'over', 'shall', 'if', 'since', "what's", 'a', 'some', 'the', "shouldn't", 'we', 'where', 'any', 'an', 'she', 'them', "hadn't", "he'll", "he's", 'who', "it's", 'he', 'ourselves', 'also', 'you', 'most', 'were', "i'll", 'r', 'with', 'at', 'yourselves', 'have', 'when', 'www', "mustn't", 'about', 'up', 'did', "let's", 'are', 'few', 'be', 'being', 'too', 'their', 'cannot', 'more', 'to', "here's", "why's", 'having', "didn't", 'hers', 'no', 'in', 'under', 'how', 'again', "he'd", 'her', 'so', "they're", "she'll", 'against', 'however', 'my', "couldn't", "i'm", "wouldn't", "she'd", "aren't", 'been', 'above', 'before', 'those', "we'd", 'such', "hasn't", "isn't", 'not', 'only', 'http', "they'd", 'nor', 'because', 'i', "you'd", 'which', 'they', "who's", 'it', 'could', 'into', "can't", 'out', 'while', 'down', "how's", 'ought', 'am', "don't", 'each', 'himself', 'through', "i've", 'whom', 'from', 'is', 'therefore', 'themselves', 'our', 'all', 'but', 'same', "shan't", "you're", 'as', 'between', 'has', 'then', "we've", 'both', 'its', 'these', 'should', 'like', 'or', "they've", 'do', 'theirs', "weren't", 'below', 'yours', 'com', 'for', 'than', 'here', 'get', 'that', "wasn't", 'your', 'further', 'doing', 'during'}

2.通过w.fit_words(参数为字典类型)+Counter(参数可以是字符串,也可以是可迭代的对象,返回字典类型)+jieba(参数是字符串,返回是generator类型)。下面代码中会按照关键字+词频的阈值去自定义过滤,不符合条件的词频(和字典数据知识点的用法一样),以上2种处理过滤的结果是一样。个人觉得使用w.fit_words比W.generate生成词云图,要更直观一点,因为它可以根据词频的大小,在词云图上反应出字体的大小。简单说某个词频非常高,那么它的字号在词云图上显示的就越大。


# -*- coding: utf-8 -*-
# @Author : 小红牛
# 微信公众号:WdPython
import re
import jieba
from collections import Counter
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt# 1.读取文本
text = '杨过是欧阳锋的义子,他的黯然销魂掌,可以和郭靖的降龙十八掌媲美。'
# 使用正则,只取中文的字符,过滤英文数字,各种标点符号等等
text = re.findall('[\u4e00-\u9fff]+', text)
text = ''.join(text)
print('1.只取中文文本:'.center(50, '-'))
print(text)
# 2.分词
cut_word = jieba.cut(text, cut_all=False)
word_freq = Counter(cut_word)
print('2.过滤前的分词词频:'.center(50, '-'))
print(word_freq)# 自定义定义过滤条件
min_freq = 0  # 最小词频阈值
exclude_words = {'是', '的', '和', '可以', '他'}  # 要排除的词列表# 过滤词频字典
filtered_word_freq = {word: freq for word, freq in word_freq.items()if freq >= min_freq and word not in exclude_words}print('3.过滤后词频:'.center(50, '-'))
print(filtered_word_freq)# 4.创建WordCloud对象并生成词云
w = WordCloud(background_color='WHITE', height=400, width=700,font_path='simkai.ttf')w.fit_words(filtered_word_freq)
# 5.保存词云图图片
w.to_file('cloud.png')
# 显示词云图
plt.imshow(w)
plt.axis('off')
plt.show()
print('词云图生成完成。')

输出内容:

--------------------1.只取中文文本:---------------------
杨过是欧阳锋的义子他的黯然销魂掌可以和郭靖的降龙十八掌媲美
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\Ms-xiao\AppData\Local\Temp\jieba.cache
Loading model cost 1.151 seconds.
Prefix dict has been built successfully.
--------------------2.过滤前的词频:---------------------
Counter({'的': 3, '杨过': 1, '是': 1, '欧阳锋': 1, '义子': 1, '他': 1, '黯然销魂': 1, '掌': 1, '可以': 1, '和': 1, '郭靖': 1, '降龙十八掌': 1, '媲美': 1})
---------------------3.过滤后词频:---------------------
{'杨过': 1, '欧阳锋': 1, '义子': 1, '黯然销魂': 1, '掌': 1, '郭靖': 1, '降龙十八掌': 1, '媲美': 1}
词云图生成完成。

完毕!!感谢您的收看

----------★★历史博文集合★★----------

我的零基础Python教程,Python入门篇 进阶篇 视频教程 Py安装py项目 Python模块 Python爬虫 Json Xpath 正则表达式 Selenium Etree CssGui程序开发 Tkinter Pyqt5 列表元组字典数据可视化 matplotlib 词云图 Pyecharts 海龟画图 Pandas Bug处理 电脑小知识office自动化办公 编程工具 NumPy Pygame

http://www.zhongyajixie.com/news/14320.html

相关文章:

  • 武汉光谷做网站哪家好香港域名注册网站
  • 潍坊网站建设一品网络sem竞价推广是什么意思
  • 盐城做网站价格制作网站平台
  • 网站制作需要多少钱客服微信管理系统平台
  • 营销网站设计实验网站推广的概念
  • 建网站的域名厦门关键词排名优化
  • discuz!网站模板个人网站该怎么打广告
  • 网站建设时间安排济宁百度竞价推广
  • 便宜网站建设多少钱百度指数功能模块有哪些
  • 文件网站建设太原seo排名外包
  • adobe网站开发苏州优化网站公司
  • 网站制作的流程是什么如何做好一个网站
  • 网站开发 平面设计seo的概念
  • mvc电子商务网站开发企业品牌推广方案
  • 马鞍山做公司网站的微信引流推广怎么做
  • 邯郸wap网站建设价格怎样制作一个网页
  • 东莞英文网站制作宁波seo搜索优化费用
  • 全球搜索引擎网站百度客服24小时人工服务在线咨询
  • 网站计数器代码js网站推广的几种方法
  • 如何制作数据库网站企业培训课程清单
  • 做网站一般是怎么盈利互联网产品运营
  • 网站模板的好处迅雷磁力链bt磁力天堂下载
  • 免费的com域名注册网站seo推广方案
  • 官方网站做兼职百度搜索引擎官网
  • 已有网站开发app客户端长春网站建设定制
  • 学习网站建设搜索引擎营销的名词解释
  • 小说网站开发需求分析seo1搬到哪里去了
  • wordpress 仿新浪微博汕头seo优化公司
  • 无代码网站建设软件开发培训
  • 工作做网站新闻发稿平台