当前位置:网站首页>数据可视化-《白蛇2:青蛇劫起》(2)
数据可视化-《白蛇2:青蛇劫起》(2)
2022-07-26 10:53:00 【python小渣渣】
目录
这边这个前提工作我们在数据可视化-《白蛇2:青蛇劫起》(1)中已经运行过了,在这边再次放一下,方便观看使用,详情看数据可视化-《白蛇2:青蛇劫起》(1)中的步骤后再过来观看更有连续感。
工具包引入:
#数据处理
import numpy as np
import pandas as pd
#可视化
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
读取表格
df = pd.read_excel(r"C:\Users\1\Desktop\数据分析\白蛇(含省份)数据.xlsx")可视化分析
4、一周各天评论量
首先我们进行查看, 一周内各天评论量,代码如下:
df['评论时间'].dt.dayofweek.value_counts()#默认0星期一;1星期二可以看到 每天的具体评论量,其中0默认为星期一,1默认为星期二以此类推。

在这里因为上面的默认跟我们平常的习惯不大相同,所以我们对它进行加1操作。
df['星期'] = df['评论时间'].dt.dayofweek+1
comment_week = df.groupby('星期')['评论'].count()拓展一下
做可视化图形时,我们可以直接拿系统中的颜色,代码如下
colors = sns.color_palette('husl')#可直接拿系统里面的颜色
colors
#下图色块分别是从0,1,2,3,4,5排序进行索引
做一个week_day_map的字典,后面使用map()函数进行调用
week_day_map = {
1:'星期一',2:'星期二',3:'星期三',4:'星期四',5:'星期五',6:'星期六',7:'星期日'
}
plt.figure(figsize=(12,5))#figure像素为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)#设定y轴的界限
_ = plt.xticks(comment_week.index,comment_week.index.map(week_day_map))
plt.title('一周各天评论量')
plt.xlabel('天')
plt.ylabel('评论量')运行后的结果如下,我们可以看到一周内 每天的评论量。

5、主要角色热度分析
在这里我们将主要角色都罗列出来,并用join进行连接。
names = ['小白','小青','许仙','法海','司马','孙姐','牛头帮主','蒙面男子','宝青坊主','书生']
#join进行拼接
temp = '和'.join(names)
temp
#字符串的count方法,是统计这个字符串,出现某个子串的次数
temp.count('小')
学会了join,我们现在可以将评论进行连接,采用字典的方式展现它们的姓名以及受到的评论次数。采用柱状图表示,在进行排列。代码如下 :
content = ''.join(df['评论'].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=['姓名','次数'])
#从大到小进行排列
names_counter.sort_values('次数',inplace=True,ascending=False)
plt.figure(figsize=(12,5))
plt.bar(names_counter['姓名'],names_counter['次数'])
plt.title('主要角色热度评价')
plt.xlabel('角色名称')
plt.ylabel('评论次数') 运行结果可以清楚看到评论小青的人数居多,书生、蒙面男子、牛头帮主极少。
6、可视化地图边界
将每个省份的评论量进行计算,通过map来展示各个省份评论,标题命名,从而让用户能够快速、直观的看到结果。代码如下:
data = df['省份'].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="评论数量的地域分布"),
visualmap_opts=opts.VisualMapOpts(max_=2209,min_=53,range_color=['pink','lightpink','blue'])
)
)
c.render_notebook()

还没有结束,继续看下一篇 数据可视化-《白蛇2:青蛇劫起》(3)
边栏推荐
- 27.移除元素
- 面试过程中,面试官是如何考察Rust工程师的水平?
- Newbie sees the source code arraydeque
- Interview knowledge points
- -bash: ./build.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录
- Kali view IP address
- 为什么需要自动化测试?软件测试师带你测评不同软件测试工具
- MFC中0x003b66c3 处有未经处理的异常: 0xC000041D: 用户回调期间遇到未经处理的异常
- Wechat official account message notice "errCode": 40164, "errmsg": "invalid IP
- LinkedList of source code
猜你喜欢

Classified by the number of 1 in binary number

菜鸟看源码之LinkedBlockingQueue

mysql20210906

按二进制数中1的个数分类

Software Testing Overview: the background, essence and process of software testing

菜鸟看源码之HashTable

Wechat official account message notice "errCode": 40164, "errmsg": "invalid IP

Capture ZABBIX performance monitoring chart with selenium

@Notblank, @notnull, @notempty differences and uses

LinkedList of source code
随机推荐
二叉树的遍历 递归+迭代
Logging learning final edition - configured different levels of log printing colors
logging 学习最终版-配置的不同级别日志打印的颜色
Visual conversion of nmap vulnerability scanning results
Shell script fails to execute repeatedly automatically
Toolstrip border removal
软件测试综述之软件测试的背景、实质、软件开发的过程
Sword finger offer (8): jump the steps
pytest pytest.ini配置 用例分组 用例跳过
Connection between PLC and servo motor
Solve the problem of the popularity of org.apache.commons.codec.binary.base64
Fragment lazy load
Pengge C language lesson 4 (3)
pytest pytest. Ini configuration case grouping case skipping
Sword finger offer (twenty): stack containing min function
Bash shell learning notes (III)
ESXi6.5补丁更新
LinkedList of source code
1837.K进制表示下的各位数字总和
0x00007ffd977c04a8 (qt5sqld.dll) (in a.exe): 0xc0000005: an access violation occurred when reading position 0x0000000000000010