大家早好、午好、晚好吖~
import requests # 发送网络请求模块
import json
import pprint # 格式化输出模块
import pandas as pd # 数据分析当中一个非常重要的模块
今天要爬取的目标数据
https://news.qq.com/zt2020/page/feiyan.htm#/
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_=1638361138568'
response = requests.get(url, verify=False)
json_data = response.json()['data']
json_data = json.loads(json_data)
china_data = json_data['areaTree'][0]['children'] # 列表
data_set = []
for i in china_data:
data_dict = {}
# 地区名称
源码、解答、教程、资料有需要可以口裙:832157862
data_dict['province'] = i['name']
# 新增确认
data_dict['nowConfirm'] = i['total']['nowConfirm']
# 死亡人数
data_dict['dead'] = i['total']['dead']
# 治愈人数
data_dict['heal'] = i['total']['heal']
# 死亡率
data_dict['deadRate'] = i['total']['deadRate']
# 治愈率
data_dict['healRate'] = i['total']['healRate']
data_set.append(data_dict)
df = pd.DataFrame(data_set)
df.to_csv('data.csv')
from pyecharts import options as opts
源码、解答、教程、资料有需要可以口裙:832157862
from pyecharts.charts import Bar,Line,Pie,Map,Grid
df2 = df.sort_values(by=['nowConfirm'],ascending=False)[:9]
df2
line = (
Line()
.add_xaxis(list(df['province'].values))
.add_yaxis("治愈率", df['healRate'].values.tolist())
.add_yaxis("死亡率", df['deadRate'].values.tolist())
.set_global_opts(
title_opts=opts.TitleOpts(title="死亡率与治愈率"),
)
)
line.render_notebook()
bar = (
Bar()
.add_xaxis(list(df['province'].values)[:6])
.add_yaxis("死亡", df['dead'].values.tolist()[:6])
.add_yaxis("治愈", df['heal'].values.tolist()[:6])
.set_global_opts(
源码、解答、教程有需要可以口裙:832157862
title_opts=opts.TitleOpts(title="各地区确诊人数与死亡人数情况"),
datazoom_opts=[opts.DataZoomOpts()],
)
)
bar.render_notebook()
好了,我的这篇文章写到这里就结束啦!
有更多建议或问题可以评论区或私信我哦!一起加油努力叭(ง •_•)ง
喜欢就关注一下博主,或点赞收藏评论一下我的文章叭!!!