当前位置:网站首页>【笔记】结巴分词绘制词云图
【笔记】结巴分词绘制词云图
2022-07-30 01:43:00 【Sprite.Nym】
一、结巴分词的三种模式
(1)精确模式:把最有可能组成词语的词切开,没有冗余单词。
(2)全模式:把所有可能组成词语的词切开,有冗余单词。
(3)搜索引擎模式:在精确模式的基础上,对长词再次切分,适合用于搜索引擎分词。
二、正则提取数据
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# 导数据
douyin = pd.read_csv('data/douyin.csv')
# 正则提取,并达到MySQL中group_concat的效果
temp = douyin['signature'].str.extractall(r'[^一-龥]*([一-龥]+)[^一-龥]*').copy()
temp = temp.reset_index().groupby('level_0').agg({
0:list})[0].apply(lambda x: ','.join(x))
# 将提取出来的字符串进行分词,并剔除停用词
result0 = ','.join([','.join(jieba.lcut(statement)) for statement in temp]).split(',')
result1 = [x for x in result0 if x not in stop_words]
# 创建词频Series对象
important_words = pd.Series(result1).value_counts()[1:200]
important_words
三、绘制
# 导入绘制所需参考图像
bgimg = np.array(Image.open('data/bgimg.png'))
# 以参考图像的颜色作为词云图颜色
genclr = wordcloud.ImageColorGenerator(bgimg)
# 创建慈云图对象
wc = wordcloud.WordCloud(
# 指定字体路径
font_path='data/FZZJ-LongYTJW.TTF',
# 指定背景颜色
background_color='white',
# 指定最大词数
max_words=200,
# 指定最大和最小字号
max_font_size=300,
min_font_size=5,
# 指定随机种子
random_state=4,
# 指定词云图轮廓参考哪张图
mask=bgimg,
# 指定词云图颜色
color_func=genclr)
# 渲染文字
wc.generate_from_frequencies(important_words)
# 使用plt展示词云图
plt.figure(figsize=(24,24))
plt.imshow(wc)
plt.axis('off')

边栏推荐
- 2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
- 将镜像推送到阿里云私有仓库
- App测试需要测什么
- Teach you how to achieve a flowing gradient border
- 帽式滑环的工作原理
- Typora transparent background image
- my creative day
- OSPF shamlink 解决后门链路问题
- 神经网络迭代次数的一个近似关系
- [Flutter] Flutter preloading of mixed development solves the problem of slow page loading for the first time
猜你喜欢

CAPL中的键值对(hash)数据类型

LeetCode 2342. 数位和相等数对的最大和

Interviews with big factories under the trend of layoffs: "ByteDance"

App测试需要测什么

图解LeetCode——593. 有效的正方形(难度:中等)

Recommendation system: collection of user "behavioral data" [use Kafka and Cassandra to process data] [if it overlaps with business data, it also needs to be collected independently]

1.2Recyclerview实现Item点击事件
![[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.](/img/29/a6ec7e00df289f68dcd39fe4f35fd3.png)
[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.

Postgresql daily operation and maintenance skills, suitable for beginners

解决vscode的Network不显示问题
随机推荐
CMake Tutorial 巡礼(1)_基础的起点
Elephant Swap:借助ePLATO提供加密市场的套利空间
数据流图、数据字典
SwiftUI SQLite数据库存储使用教程大合集(2022年版)
AI落地难?云原生助力企业快速应用机器学习 MLOps
短期风电预测(Matlab代码实现)
「MySQL」- 基础增删改查
经济衰退时期的对比:如今更像历史上的哪段时期?
记笔记!电源自动测试系统测试电源纹波详细方法
LABVIEW详细介绍:LABVIEW是什么软件?都可以干什么?
Performance Testing Theory 1 | Sorting out difficult problems in performance testing
What to test for app testing
CAPL中的键值对(hash)数据类型
可惜了!规模这么大的上市公司说散就散了
【LeetCode每日一题】——637.二叉树的层平均值
The role of interface testing
Fabric 编写案例 链码
fluttter学习之ButtonStyle 、MaterialStateProperty
泰克Tektronix示波器软件TDS2012|TDS2014|TDS2022上位机软件NS-Scope
把@Transactional事务注解用到如此炉火纯青,真的强!