新冠状病毒

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; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
    }
    r = requests.get(url,headers)
    #判断是否访问成功
    if r.status_code == 200:
        #返回json数据,获取data项
        return json.loads(json.loads(r.text)['data']) 
    data_dict = getData
    
province_list = list()
for province in data_dict.get('areaTree')[0][''children]:
    province_info = province['total']
    province_info['name'] = province['name']
    province_list.append(province_info)
province_df = pd.DataFrame(province_list)

#按照数据类型删除列
#include=包含什么类型,exclude=不包含什么类型
province_df = province_df.select_dtypes(exclude=['bool'])

#把省份的名称和累计确诊的数据转换成list
province_name = province.name.tolist()
province_confirm = province_df.confirm.tolist()

from pyecharts.charts import Map
from pyecharts import options as opts  #配色 标题

#颜色配置 必须是一个list包裹dict
pieces = [
    {'min':1,'max':9,'color':'#FFE0E0'},
    {'min':10,'max':99,'color':'#FFC0C0'},
    {'min':100,'max':499,'color':'#FF9090'},
    {'min':500,'max':999,'color':'#FF6060'},
    {'min':1000,'max':9999,'color':'#FF3030'},
    {'min':10000,'color':'#DD0000'},
    
]

china_map = Map()
#定义地图,填充数据
china_map.add('全国疫情分布',[tup for tup in zip(province_name,province_confirm)],'china')
#填充
china_map.set_global_opts(title_opts=opts.TitleOpts(title='中国加油!武汉加油!'),\
                          visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=pieces))
#打印地图
china_map.render_notebook()

你可能感兴趣的:(数据分析,数据分析)