当前位置:网站首页>Data visualization - White Snake 2: black snake robbery (3)
Data visualization - White Snake 2: black snake robbery (3)
2022-07-28 00:45:00 【Python slag】
Catalog
7 Film review word cloud analysis
from PIL Import Image Pictures of the
Graph of word cloud operation results :
Drink a bottle of Wangzai, let's continue ......

7 Film review word cloud analysis
download
pip install jieba ( If a download fails , Just a few more times , If you can't, check online )
pip install jieba
collections Statistical word quantity
import jieba
import wordcloud
import collectionslcurt Cut the string in a list
jieba.lcut(df[' Comment on '][0])The operation result is as follows :

I have a stop phrase file (stopwords.txt), You can also find resources on the Internet .
Put stop words in stop_words in , And put \n Cut off .
The code is shown as follows :
with open('stopwords.txt','r',encoding='utf-8')as fp:
words=fp.readlines()
stop_words = []
for word in words:
w = word.strip('\n')# Put the backslash in the word n Cut off
stop_words.append(w)
stop_wordsOperation result diagram :
Stop word processing :
Next, we begin to deal with stop words ,word_list = jieba.lcut(comment).
Then on word_list Do traversal , Remove the stop words ( You can go online to find stop words Resources )
# Stop word processing
good_words =[]
for comment in df[' Comment on ']:
word_list = jieba.lcut(comment)
# Yes word_list Do traversal , Remove the stop words ( Go online to find stop words Resources )
for word in word_list:
if word not in stop_words:
good_words.append(word)
In the following code, we carry out font type ( Mona Chao gang Heijian .ttf) Application , And configure the word number data to the word cloud object , Finally show the picture . The code is as follows :
c = collections.Counter(good_words)
wc = wordcloud.WordCloud(font_path=' Mona Chao gang Heijian .ttf',width=500,height=300,
background_color='white',
max_font_size=200,
min_font_size=5,
max_words=1000)
# Configure word number data to the word cloud object
wc.generate_from_frequencies(c)
# Show the image
plt.imshow(wc)
The operation results are as follows : At this time, the size and color of word cloud are given by the system by default , As shown in the figure :
,
from PIL Import Image Pictures of the
from PIL import ImageBased on the last word cloud code , We added a love background picture to it , And define a color for word cloud from dark to light , Then turn off the horizontal and vertical coordinates beside the figure . The code is as follows :
back_image = Image.open(r'C:\Users\1\Desktop\1.png')
c = collections.Counter(good_words)
# Adjust canvas
plt.figure(figsize=(12,7))
wc = wordcloud.WordCloud(font_path=' Mona Chao gang Heijian .ttf',width=500,height=300,
background_color='white',
# The background color is white
max_font_size=200,
min_font_size=5,
# Adjust the size of words to 5-200
max_words=1000,
# The maximum number of words that can be accommodated is 1000
mask=np.array(back_image),
# Put pictures
colormap=sns.dark_palette('pink',as_cmap=True)
# The color of the tone cloud is a deep to light purple , Remember to set up as_cmap=True This parameter , Otherwise, the code cannot recognize this as a color parameter
)
# Configure word number data to the word cloud object
wc.generate_from_frequencies(c)
# Show the image
plt.imshow(wc)
# Turn off the horizontal and vertical axes next to the diagram
plt.axis('off')Graph of word cloud operation results :

So far, data visualization -《 White Snake 2: The green snake robbed 》 This concludes the analysis . Friends who feel useful give me a little praise , finger heart .

边栏推荐
- Yongzhou plant cell laboratory construction layout plan
- Understand the parental delegation model
- CSDN21天学习挑战赛
- ASML推出第一代HMI多光束检测机:速度提升600%,适用于5nm及更先进工艺
- Camera and lidar calibration: gazebo simulation livox_ camera_ lidar_ Calibration ---- external parameter calibration calculation and result verification
- The influence of head zeroing and tail zeroing on FFT output
- 基于Unittest的ddt+yaml实现数据驱动机制
- require、loadfile、dofile、load、loadstring
- In the first quarter of 2020, the wearable market shipped 72.6 million units, with apple occupying nearly 30% of the market share
- 基本初等函数
猜你喜欢

The second uncle cured my spiritual internal friction and made me angry out of station B

In the third week of July, the list of feigua data station B up main ranking list was released!

从第二层到第三层

迷惑的单片机矩阵按键

推进云网融合,筑路数字经济:英特尔亮相第五届数字中国建设峰会-云生态大会

Buildforge materials

MATLAB 文件夹前面的+和@是干啥的 命名空间与函数的重载
![[leetcode] 547. Number of provinces (medium)](/img/15/d49d18151c47e318fe7acabdd616e6.png)
[leetcode] 547. Number of provinces (medium)

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

MATLAB如何将k线图设置为经典红绿配色?
随机推荐
Set 数据构造函数
OpenVINO整合TensorFlow实现推理加速
Yongzhou plant cell laboratory construction layout plan
Analysis and solution of errors in symbols uploading when baget manages packages
图片提取文字很神奇?试试三步实现OCR!
Intel releases open source AI Reference Suite
Remote monitoring of pump station
Basic operations of MySQL database (I) --- Based on Database
How does matlab set the K-line diagram to classic red and green color matching?
这种动态规划你见过吗——状态机动态规划之股票问题(中)
MATLAB | MATLAB地形生成:矩形迭代法 · 傅里叶逆变换法 · 分形柏林噪声法
小程序助力智能家居生态平台
Jmeter 如何解决乱码问题?
BuildForge 资料
Basic elementary function
The server is poisoned - the dish is the original sin
mysql分表之后怎么平滑上线?
单片机之led、数码管与按键
MySQL limit使用及超大分页问题解决
map集合
