[Sentiment Scoring + Sentiment Judgment + Word Cloud Map] Python Sentiment Analysis Li Ziqi Channel Video Popular English Comments

content

1. Background of the event

Second, python code explanation

3. Synchronized explanation video

Fourth, get the python source file


1. Background of the event

Today is 2021.12.2, it has been more than 4 months since Li Ziqi broke up. This is the last video I uploaded on July 14, 2021 on the YouTube Li Ziqi YouTube channel. I recorded the video below Comments from netizens all over the world, netizens all over the world collectively looked forward to Li Ziqi's return, and burst into tears instantly.

Zhihu Video - Li Ziqi Channel Video Popular Comments

How to analyze the comment attitude and public opinion orientation of netizens in response to the popular comments of netizens all over the world? So I tried to do sentiment analysis with python and came to some public opinion-oriented conclusions.

Second, python code explanation

Below, through the python code ( part of the core code ) decomposed one by one, how this sentiment analysis is implemented:

First, import the required libraries:

import pandas as pd  # 数据分析库
from textblob import TextBlob  # 英文情感分析库
import matplotlib.pyplot as plt  # 画图
from wordcloud import WordCloud  # 绘制词云图
from wordcloud import ImageColorGenerator
from PIL import Image
import numpy as np

Then, read the excel comment data through pandas ( the crawler code will not be explained, friends who are interested in the crawler code can chat with me privately )

file = "李子柒评论.xlsx"
df = pd.read_excel(file, usecols=[1, 2, 3, 4, 5]) #读取评论数据
v_cmt_list = df['text'].values.tolist() # 把评论字段转换为list
print('length of v_cmt_list is:{}'.format(len(v_cmt_list)))

Here is the code for sentiment analysis:

# 情感分析
score_list = []  # 情感评分值
tag_list = []  # 打标分类结果
for comment in v_cmt_list:
    tag = ''
    judge = TextBlob(comment)
    sentiments_score = judge.sentiment.polarity
    score_list.append(sentiments_score)
    if sentiments_score < 0:
        tag = '消极'
    elif sentiments_score == 0:
        tag = '中性'
    else:
        tag = '积极'
    tag_list.append(tag)
df['情感得分'] = score_list
df['分析结果'] = tag_list
df.to_excel('情感分析结果.xlsx', index=None)

Check out the sentiment analysis results:

df.groupby(by=['分析结果']).count()['text']  # 分组统计情感分析结果

The results show that neutral and positive words account for more than half, which means that most netizens still like Li Ziqi's videos.

Finally, the code for word cloud map drawing:

# 绘制词云图
stopwords = ['the', 'a', 'and', 'of', 'it', 'her', 'she', 'if', 'I', 'is', 'not', 'your', 'there', 'this',
             'that', 'to', 'you', 'in', 'as', 'for', 'are', 'so', 'was', 'but', 'with', 'they', 'have']  # 停用词
coloring = np.array(Image.open("lzq3.jpeg"))
backgroud_Image = coloring  # 读取背景图片
wc = WordCloud(
    scale=3,  # 图片大小,清晰度
    background_color="white",  # 背景颜色
    max_words=1000,  # 词数量
    font_path='/System/Library/Fonts/SimHei.ttf',  # Mac字体文件路径,根据实际情况替换
    # font_path="C:\Windows\Fonts\simhei.ttf",  # Win字体文件路径,根据实际情况替换
    stopwords=stopwords,  # 停用词
    mask=backgroud_Image,  # 背景图片
    color_func=ImageColorGenerator(coloring),  # 根据原始图片颜色生成词云图颜色
    max_font_size=100,  # 设置字体最大值
    random_state=240  # 设置有多少种随机生成状态,即有多少种配色方案
)
wc.generate(v_cmt_str)  # 生成词云图
wc.to_file('词云结果图.png')  # 保存图片文件
display(Image.open('lzq3.jpeg'))  # 显示原始图片
wc.to_image()  # 显示词云图

The final display effect of the word cloud map is as follows:

It should be noted here that the code color_func=ImageColorGenerator(coloring) can generate the color of the word cloud image according to the color of the original image. Careful friends should be able to see that the color ratio of the word cloud map is very close to the color ratio of the original picture.

3. Synchronized explanation video

Instructional video:

3 minutes to explain using python code, sentiment analysis Li Ziqi YouTube channel comment

Fourth, get the python source file

Friends who love to learn and want to get the complete python code file, follow my WeChat public account " Old Boy's Ordinary Road ", and reply " Li Ziqi Sentiment Analysis " in the background to get the complete python source code and result file. Click on the link to go directly↓

[Python Sentiment Analysis] Sentiment Analysis with Python , which is https://mp.weixin.qq.com/s?__biz=MzU5MjQ2MzI0Nw==&mid=2247484565&idx=1&sn=ffd0f5e69a490f3fcf82109ea637b721&chksm=fe1e1075c9699963af56beda45cc010a1b515f87aa68a6443878a8e575e6ca57b53f4b449475&payreadticket=HLFBI00L_inc8Ul4LG_PKeZ9lkYuDEDLi03J5hjohpGC_by7jTbbayE1YtcMmWfrWKtLd7Y#rd


I am Ma Ge, and I have tens of thousands of fans on the entire network. Welcome to exchange python technology together.

Search " Ma Ge python said " on various platforms: Zhihu, Bilibili, Xiaohongshu, Sina Weibo.

Guess you like

Origin blog.csdn.net/solo_msk/article/details/124224283