疫情分析:获取全球各大洲的数据

import pandas as pd
import requests
import time
import json
import numpy as np
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker

# url='https://lab.isaaclin.cn/nCoV/api/area?latest=0'
url='https://view.inews.qq.com/g2/getOnsInfo?name=disease_other'

def GetHtmlText(url):
    try:
        res = requests.get(url,timeout = 30)
        res.raise_for_status()
        res.encoding = res.apparent_encoding
        return res.text
    except:
        return "Error"
data = json.loads(requests.get(url=url).json()['data'])
foreignlist = data["foreignList"] 

continent=[]
confirm=[]
confirmAdd=[]
heal=[]
dead=[]

for country in foreignlist:
    continent.append(country['continent'])
    confirm.append(country['confirm'])
    confirmAdd.append(country['confirmAdd'])
    heal.append(country['heal'])
    dead.append(country['dead'])
json_data={'continent':continent,'confirm':confirm,'confirmAdd':confirmAdd,'heal':heal,'dead':dead}
# json_data=json.dumps(json_data)
df=pd.DataFrame(json_data)

data=df.groupby('continent')['confirm'].agg([np.sum]) 

你可能感兴趣的:(疫情分析)