tableau 实时展示疫情数据(未完待续)

先学习如何使用API数据接口

https://lab.isaaclin.cn/nCoV/ API接口、参数
城市名称数据province_cities.json”在下面的GitHub中
https://github.com/hack-fang/nCov


# 获取某省份各市数据数据
import json
import time
import requests
import json
import os
from flask import Flask, render_template, jsonify
from pyecharts.charts import Map,Bar
from pyecharts import options as opts
path = os.path.join(os.path.dirname( os.path.abspath('C:\\Users\\lining\\Desktop\\myjob\\My_SQL\\huigui\\通过API获取数据.ipynb')),
                    "province_cities.json")
#path = os.path.join(os.path.dirname('C:\\Users\\lining\\Desktop\\myjob\\My_SQL\\huigui'), "province_cities.json")
with open(path, "r",encoding="utf-8") as f:
    province_city_fixed = json.load(f)
def update_province_data(province):
    baseUrl = "https://lab.ahusmart.com/nCoV/api/"
    url = baseUrl +'area?latest=1&province='+province
    province_data = json.loads(requests.get(url).text)
    province_data['time'] = time.strftime(
        "%m-%d %H:%M", time.localtime(time.time()))
    # 取最新一条统计数据
    latest_data = province_data["results"][0]
    cities_data = []
    for  c  in latest_data["cities"]:
        city_data = []
        city_data.append(province)
        
        # 先在修正表中找
        '''
        if province_city_fixed[province][c["cityName"]]!=None:
            city_data.append(province_city_fixed[province][c["cityName"]])
        # 没有则延用原始名称
        else:
            city_data.append(c["cityName"])'
        '''
        try:
            city_data.append(province_city_fixed[province][c["cityName"]])
        except:
            city_data.append(c["cityName"])
        else:
            pass
            
            
        city_data.append(c["confirmedCount"])
        cities_data.append(city_data)
    return cities_data

原作者的代码在读取新疆数胡杨河数据时报错,本人已用try except完善,并转换成pandas dataframe

xj= pd.DataFrame(list(update_province_data('新疆维吾尔自治区')),columns={'省份','城市','确诊人数'})
xj


新疆.png

df_empty = pd.DataFrame(columns={‘省份’,’城市’,’确诊人数’})

···
数据仓库 https://github.com/BlankerL/DXY-2019-nCoV-Data/blob/master/DXYArea.csv
https://github.com/hack-fang/nCov/blob/master/app.py
deepwindlee/nCov: 全国及各省新型肺炎疫情情况图 https://github.com/deepwindlee/nCov
https://github.com/search?utf8=%E2%9C%93&q=2019%E6%96%B0%E5%9E%8B%E5%86%A0%E7%8A%B6%E7%97%85%E6%AF%92&type=

https://www.jianshu.com/p/90ee6e07ef81

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论