当前位置:网站首页>Data visualization - White Snake 2: black snake robbery (2)
Data visualization - White Snake 2: black snake robbery (2)
2022-07-26 11:17:00 【Python slag】
Catalog
4、 Comments per day of the week
5、 Heat analysis of main roles
The premise here is data visualization -《 White Snake 2: The green snake robbed 》(1) Has been run in , Put it here again , Easy to watch and use , See data visualization for details -《 White Snake 2: The green snake robbed 》(1) After the steps in, come and watch more continuously .
Toolkit introduction :
# Data processing
import numpy as np
import pandas as pd
# visualization
import matplotlib.pyplot as plt
import seaborn as sns
from pyecharts.charts import Map
from pyecharts import options as opts
from pyecharts.globals import ThemeType, SymbolType, ChartType
Read the form
df = pd.read_excel(r"C:\Users\1\Desktop\ Data analysis \ White Snake ( Including provinces ) data .xlsx")Visual analysis
4、 Comments per day of the week
First, let's check , Comments per day in a week , The code is as follows :
df[' Comment on time '].dt.dayofweek.value_counts()# Default 0 Monday ;1 Tuesday You can see Specific comments per day , among 0 The default is Monday ,1 The default is Tuesday, and so on .

Here, because the default above is different from our usual habits , So we add it 1 operation .
df[' week '] = df[' Comment on time '].dt.dayofweek+1
comment_week = df.groupby(' week ')[' Comment on '].count()Expand the
When making visual graphics , We can directly take the color in the system , The code is as follows
colors = sns.color_palette('husl')# You can directly take the color in the system
colors
# The color patches in the following figure are from 0,1,2,3,4,5 Sort and index 
Make one week_day_map Dictionary , Use... In the back map() Function to call
week_day_map = {
1:' Monday ',2:' Tuesday ',3:' Wednesday ',4:' Thursday ',5:' Friday ',6:' Saturday ',7:' Sunday '
}
plt.figure(figsize=(12,5))#figure The pixel is 12×5
plt.plot(comment_week.index,comment_week.values,color=colors[5])
plt.bar(comment_week.index,comment_week.values,color=colors[0])
plt.ylim(0,5000)# Set up y The boundaries of the shaft
_ = plt.xticks(comment_week.index,comment_week.index.map(week_day_map))
plt.title(' Comments per day of the week ')
plt.xlabel(' God ')
plt.ylabel(' Comment quantity ')The results after running are as follows , We can see in a week Comments per day .

5、 Heat analysis of main roles
Here we will list the main roles , And use join Connect .
names = [' The small white ',' indigo plant ',' Xu Xian ',' Fahai ',' Sima ',' Sister sun ',' Tauren sect leader ',' Masked man ',' Baoqing workshop leader ',' Scholar ']
#join Splicing
temp = ' and '.join(names)
temp
# A string of count Method , Is to count this string , The number of times a substring appears
temp.count(' Small ')
Learned to join, We can now link comments , Use a dictionary to show their names and the number of comments received . Use histogram to show , Arranging . The code is as follows :
content = ''.join(df[' Comment on '].values.tolist())
name_counts = []
for name in names:
count = content.count(name)
name_counts.append((name,count))
names_counter = pd.DataFrame(data=name_counts,columns=[' full name ',' frequency '])
# Arrange from large to small
names_counter.sort_values(' frequency ',inplace=True,ascending=False)
plt.figure(figsize=(12,5))
plt.bar(names_counter[' full name '],names_counter[' frequency '])
plt.title(' Main role popularity evaluation ')
plt.xlabel(' Character name ')
plt.ylabel(' Comment frequency ') The running results clearly show that the majority of people comment on Xiaoqing , Scholar 、 Masked man 、 There are few Tauren sect leaders .
6、 Visualize map boundaries
Calculate the comment volume of each province , adopt map To show the comments of various provinces , Title naming , So that users can quickly 、 See the result intuitively . The code is as follows :
data = df[' Province '].value_counts()
c = (
Map(init_opts=opts.InitOpts())
.add("",[list(z) for z in zip(data.index.tolist(),data.values.tolist())],"china")
.set_global_opts(
title_opts=opts.TitleOpts(title=" The geographical distribution of the number of comments "),
visualmap_opts=opts.VisualMapOpts(max_=2209,min_=53,range_color=['pink','lightpink','blue'])
)
)
c.render_notebook()

It's not over yet , Go on to the next one Data visualization -《 White Snake 2: The green snake robbed 》(3)
边栏推荐
猜你喜欢

Pytest execution rules_ Basic usage_ Common plug-ins_ Common assertions_ Common parameters

UDF and analysis case of sparksql, 220725,

菜鸟看源码之HashTable

Generation and transformation of pulse waveform

ThreadPoolExecutor是怎样执行任务的

After 4 months of job search and 15 interviews, I finally got 3 offers, ranking P7+

easyui05

由浅入深搭建神经网络

postman 导出导入

232. Implement queue with stack
随机推荐
菜鸟看源码之HashTable
Linkedblockingqueue of novice source code
Basic use of logging
Mysql database advanced
QT——LCDNumber
pytest pytest.ini配置 用例分组 用例跳过
记录个人遇到的错误
List ascending and descending
easyui05
Multipartfil to file
UDF and analysis case of sparksql, 220725,
ORBSLAM2 CmakeLists文件结构解析
postman 导出导入
MFC picture control
【转载】多元高斯分布(The Multivariate normal distribution)
配置文件以rc结尾什么意思
3Dunity游戏项目实战——第一人称射击游戏
C#笔记
The assignment of member pointer defined in C structure and the use of structure pointer as member function parameter
104. Maximum depth of binary tree