数据源:https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=jQuery3410045725017118113165_1584794261784&_=1584794261785
import requests
import json
import pandas as pd
def getData():
url='https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5'
headers={
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
r=requests.get(url,headers)
res=json.loads(r.text)
data=res['data']
data_res=json.loads(data)
return data_res
data_dict=getData()
pip install pyecharts
pip install echarts-china-provinces-pypkg
data_dict.keys()
dict_keys(['lastUpdateTime', 'chinaTotal', 'chinaAdd', 'isShowAdd', 'showAddSwitch', 'areaTree', 'chinaDayList', 'chinaDayAddList', 'dailyNewAddHistory', 'dailyHistory', 'wuhanDayList', 'articleList'])
province_list=data_dict['areaTree'][0]['children']
proList=list()
for province in province_list:
pro_dict=dict()
pro_dict['name']=province['name']
pro_dict['confirm']=province['total']['confirm']
pro_dict['heal']=province['total']['heal']
pro_dict['dead']=province['total']['dead']
pro_dict['nowConfirm']=pro_dict['confirm']-pro_dict['heal']-pro_dict['dead']
proList.append(pro_dict)
province_df=pd.DataFrame(proList)
province_df
name | confirm | heal | dead | nowConfirm | |
---|---|---|---|---|---|
0 | 湖北 | 67800 | 58942 | 3139 | 5719 |
1 | 广东 | 1399 | 1325 | 8 | 66 |
2 | 河南 | 1273 | 1250 | 22 | 1 |
3 | 浙江 | 1236 | 1219 | 1 | 16 |
4 | 湖南 | 1018 | 1014 | 4 | 0 |
5 | 安徽 | 990 | 984 | 6 | 0 |
6 | 江西 | 935 | 934 | 1 | 0 |
7 | 山东 | 764 | 749 | 7 | 8 |
8 | 江苏 | 631 | 631 | 0 | 0 |
9 | 重庆 | 576 | 570 | 6 | 0 |
10 | 四川 | 542 | 536 | 3 | 3 |
11 | 北京 | 504 | 396 | 8 | 100 |
12 | 黑龙江 | 484 | 463 | 13 | 8 |
13 | 上海 | 380 | 327 | 3 | 50 |
14 | 河北 | 318 | 310 | 6 | 2 |
15 | 福建 | 303 | 295 | 1 | 7 |
16 | 香港 | 273 | 98 | 4 | 171 |
17 | 广西 | 254 | 250 | 2 | 2 |
18 | 陕西 | 248 | 239 | 3 | 6 |
19 | 云南 | 176 | 172 | 2 | 2 |
20 | 海南 | 168 | 161 | 6 | 1 |
21 | 台湾 | 153 | 28 | 2 | 123 |
22 | 贵州 | 146 | 144 | 2 | 0 |
23 | 天津 | 137 | 133 | 3 | 1 |
24 | 甘肃 | 134 | 113 | 2 | 19 |
25 | 山西 | 133 | 133 | 0 | 0 |
26 | 辽宁 | 126 | 122 | 2 | 2 |
27 | 吉林 | 93 | 92 | 1 | 0 |
28 | 新疆 | 76 | 73 | 3 | 0 |
29 | 宁夏 | 75 | 75 | 0 | 0 |
30 | 内蒙古 | 75 | 74 | 1 | 0 |
31 | 青海 | 18 | 18 | 0 | 0 |
32 | 澳门 | 17 | 10 | 0 | 7 |
33 | 西藏 | 1 | 1 | 0 | 0 |
from pyecharts.charts import Map
from pyecharts import options as opts #共用插件,控制图片大小,标题颜色等
from IPython.display import HTML
c=Map(opts.InitOpts(width='1000px',height='800px'))
province_name=[str(x) for x in province_df.name]
province_confirm=[int(x) for x in province_df.confirm]
province_heal=[int(x) for x in province_df.heal]
province_dead=[int(x) for x in province_df.dead]
province_nowConfirm=[int(x) for x in province_df.nowConfirm]
gen=[list(z) for z in zip(province_name,province_confirm)]
gen2=[list(z) for z in zip(province_name,province_heal)]
gen3=[list(z) for z in zip(province_name,province_dead)]
gen4=[list(z) for z in zip(province_name,province_nowConfirm)]
#颜色配置
pieces=[
{'max':1,'color':'#FFFFF0'},
{'min':1,'max':9,'color':'#FFE0E0'},
{'min':10,'max':99,'color':'#FEC0C0'},
{'min':100,'max':499,'color':'#FD9090'},
{'min':500,'max':999,'color':'#FC6060'},
{'min':1000,'max':9999,'color':'#FB3030'},
{'min':10000,'color':'#DD0000'},
]
c.add('全国累计确诊',gen,'china')
c.add('全国累计治愈',gen2,'china',is_selected=False)
c.add('全国累计死亡',gen3,'china',is_selected=False)
c.add('全国现有确诊',gen4,'china',is_selected=False)
c.set_global_opts(title_opts=opts.TitleOpts(title='中国加油'),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=pieces))
c.render_notebook()