大家早好、午好、晚好吖~
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()
好了,我的這篇文章寫到這裡就結束啦!
有更多建議或問題可以評論區或私信我哦!一起加油努力叭(ง •_•)ง
喜歡就關注一下博主,或點贊收藏評論一下我的文章叭!!!