当前位置:网站首页>数据可视化-《白蛇2:青蛇劫起》(3)
数据可视化-《白蛇2:青蛇劫起》(3)
2022-07-27 21:58:00 【python小渣渣】
目录
喝瓶旺仔咱们继续 ......

7影评词云分析
下载
pip install jieba (如果一次下载没成功,就多下几次,不行了就上网查)
pip install jieba
collections 统计词量
import jieba
import wordcloud
import collectionslcurt以列表形式对字符串进行切割
jieba.lcut(df['评论'][0])运行结果图如下:

我这边是有一个停用词文件(stopwords.txt),大家也可以在网上查找一下资源。
将停用词放在stop_words中,并且将停用词中的\n切掉。
代码展示如下:
with open('stopwords.txt','r',encoding='utf-8')as fp:
words=fp.readlines()
stop_words = []
for word in words:
w = word.strip('\n')#将单词中的反斜杠n切掉
stop_words.append(w)
stop_words运行结果图:
停用词处理:
接下来我们开始对停用词进行处理,word_list = jieba.lcut(comment)。
然后对word_list做遍历,去掉停用词(可去网上找停用词资源)
#停用词处理
good_words =[]
for comment in df['评论']:
word_list = jieba.lcut(comment)
#对word_list做遍历,去掉停用词(去网上找停用词资源)
for word in word_list:
if word not in stop_words:
good_words.append(word)
在下面这个代码中我们进行字体类型(蒙纳超刚黑简.ttf)的应用,并向词云对象配置词数数据,最终展示图片。代码如下:
c = collections.Counter(good_words)
wc = wordcloud.WordCloud(font_path='蒙纳超刚黑简.ttf',width=500,height=300,
background_color='white',
max_font_size=200,
min_font_size=5,
max_words=1000)
#向词云对象配置词数数据
wc.generate_from_frequencies(c)
#展示图像
plt.imshow(wc)
运行结果如下:这个时候的词云大小颜色啥的都是由系统默认给出 ,如图所示:
,
从PIL中导入Image的图片
from PIL import Image在上一个词云代码的基础上,我们给它添加了一个爱心的背景图片,并且给词云定义一种颜色由深到浅的,然后顺便将图旁边的横纵坐标关掉。代码如下:
back_image = Image.open(r'C:\Users\1\Desktop\1.png')
c = collections.Counter(good_words)
#调画布
plt.figure(figsize=(12,7))
wc = wordcloud.WordCloud(font_path='蒙纳超刚黑简.ttf',width=500,height=300,
background_color='white',
#背景颜色为白色
max_font_size=200,
min_font_size=5,
#调节词的大小为5-200
max_words=1000,
#最多能容纳词的数量为1000
mask=np.array(back_image),
#放图片
colormap=sns.dark_palette('pink',as_cmap=True)
#调词云颜色为一种颜色由深到浅的紫色,记得设置as_cmap=True这个参数,否则代码无法识别这个作为颜色参数处理
)
#向词云对象配置词数数据
wc.generate_from_frequencies(c)
#展示图像
plt.imshow(wc)
#把图旁边的横纵轴关掉
plt.axis('off')词云运行结果图:

至此数据可视化-《白蛇2:青蛇劫起》就此分析结束。觉得有用的友友们给我小小的点个赞吧,比心。

边栏推荐
- 学yolo需要什么基础?怎么学YOLO?
- 渲染问题
- mysql数据库的基本操作(二)-——基于数据表
- MATLAB | 那些你不得不知道的MATLAB小技巧(四)
- 【Leetcode】547.省份数量(中等)
- Microsoft Amazon layoffs, the economic crisis is getting closer...
- Analysis and solution of errors in symbols uploading when baget manages packages
- Camera and lidar calibration: gazebo simulation livox_ camera_ lidar_ Calibration ---- external parameter calibration calculation and result verification
- leetcode 452. Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球(中等)
- C event related exercise code.
猜你喜欢

Introduction to thesis writing | how to write an academic research paper

mysql数据库的基本操作(二)-——基于数据表

元宇宙的应用场景展示

Is it amazing to extract text from pictures? Try three steps to realize OCR!

Application scenario Display of metauniverse

服务器中毒了——菜是原罪

Implement Gobang game with C language

Matlab | those matlab tips you have to know (I)

强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会

A great thinking problem cf1671d insert a progression
随机推荐
Possible reasons why there is no voltage in the corresponding channel, but the ADC value is changing greatly and is not equal to 0
2022 latest Tiktok live broadcast monitoring full set of monitoring (V) product details monitoring
code review 工具
A great thinking problem cf1671d insert a progression
30余年的元宇宙,为我们带来了什么?
BuildForge 资料
Mqtt---mqtt.fx client software
Server open sensitive port
mysql数据库的基本操作(二)-——基于数据表
Overview of construction site selection of Yongzhou analytical laboratory
In the third week of July, the list of feigua data station B up main ranking list was released!
永州二恶英实验室建设细节查看
See how well-known enterprises use Web3 to reshape their industries
MATLAB | 那些你不得不知道的MATLAB小技巧(二)
几行代码轻松实现对于PaddleOCR的实时推理,快来get!
LeetCode_位运算_中等_137.只出现一次的数字 II
[C language] string reverse order (recursive implementation)
Implement Gobang game with C language
推进云网融合,筑路数字经济:英特尔亮相第五届数字中国建设峰会-云生态大会
MATLAB | MATLAB地形生成:矩形迭代法 · 傅里叶逆变换法 · 分形柏林噪声法
