import requests import pandas as pd url = "https://gwpre.sina.cn/interface/fymap2020_data.json?1582011487323" response = requests.get(url).json() province_list = response['data']['list'] data = [] for province in province_list: if province['name'] == '广西': for city in province['city']: data_city = {} data_city['城市'] = city['name'] data_city['积累确诊人数'] = int(city['conNum']) data_city['积累治愈人数'] = int(city['cureNum']) data_city['积累死亡人数'] = int(city['deathNum']) data_city['现有确诊人数'] = int(city['econNum']) data.append(data_city) df = pd.DataFrame(data) print(df) df.to_csv('lx.csv',index=False) from pyecharts import options as opts from pyecharts.charts import Bar,Map,Line,Scatter,EffectScatter #柱状图 bar = ( Bar() .add_xaxis(list(df['城市'].values)) .add_yaxis("积累确诊", df['积累确诊人数'].values.tolist()) .set_global_opts(title_opts=opts.TitleOpts(title="广西积累确诊人数")) .render("广西积累确诊人数.html") ) #地图 result = [] for province in province_list: if province['name'] == '广西': for city in province['city']: result.append([city['mapName'],city['conNum']]) map = ( Map() .add("城市",result,"广西") .set_global_opts(title_opts=opts.TitleOpts(title="广西积累确诊地图"), visualmap_opts=opts.VisualMapOpts(min_=0,max_=100)) .render("广西积累确诊地图.html") ) #排序前十的地区 num = df.sort_values(by='积累确诊人数',ascending=False)[0:10] c = ( Bar() .add_xaxis(list(df['城市'].values)) .add_yaxis("积累确诊",num['积累确诊人数'].values.tolist()) .set_global_opts(title_opts=opts.TitleOpts(title="广西积累确诊前十的地区"), datazoom_opts=opts.DataZoomOpts()) .render("广西疫情积累前十.html") ) #广西治愈人数与死亡人数情况对比图 line = ( Line() .add_xaxis(list(df['城市'].values)) .add_yaxis("治愈人数",df['积累治愈人数'].values.tolist()) .add_yaxis("死亡人数",df['积累死亡人数'].values.tolist()) .set_global_opts(title_opts=opts.TitleOpts(title="治愈人数与死亡人数情况对比图"), datazoom_opts=opts.DataZoomOpts()) .render("广西疫情治愈人数与死亡人数对比图") ) #现有确诊人数散点图 scatter = ( Scatter() .add_xaxis(list(df['城市'].values)) .add_yaxis("现有确诊人数",df['现有确诊人数'].values.tolist()) .set_global_opts( title_opts=opts.TitleOpts(title="广西疫情现有确诊人数散点图"), visualmap_opts=opts.VisualMapOpts(type_="size",max_=10), ) .render("广西疫情现有确诊人数散点图.html") ) #确诊人数涟漪散点图 effectScatter = ( EffectScatter() .add_xaxis(list(df['城市'].values)) .add_yaxis("积累确诊人数",df['积累确诊人数'].values.tolist()) .set_global_opts( title_opts=opts.TitleOpts(title="广西疫情积累确诊人数涟漪散点图"), visualmap_opts=opts.VisualMapOpts(max_=300) ) .render("广西疫情确诊人数涟漪散点图.html") )
期末python练习日志
于 2022-11-16 15:58:12 首次发布