您好,欢迎来到飒榕旅游知识分享网。
搜索
您的当前位置:首页使用Python实现国内疫情数据地图

使用Python实现国内疫情数据地图

来源:飒榕旅游知识分享网

本篇博客将实现国内疫情数据地图

爬取数据
import requests
import json
china_url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"

headers={
   
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win; x) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
    "Referer":"https://news.qq.com/"
}
#获取到json数据
response=requests.get(url=china_url,headers=headers).json()
#先把数据改成Python中的字典
data=json.loads(response['data'])

print(response)
#保存数据
with open('./国内疫情.json','w') as f:
    #再把字典改成json字符串
    f.write(json.dumps(data,ensure_ascii=False,indent=2))
将json数据保存到excel中
import pandas as pd
import json
#将json数据转存到excel中
#读取文件
with open("./国内疫情.json",'r',encoding="utf-8") as f:
    data=f.read()
data=json.loads(data)
#获取国内所有数据
chinaAreaDict=data['areaTree'][0]
provinceList=chinaAreaDict['children']
# print(len(provinceList))
china_citylist=[]#{
   {湖北,武汉},{湖北,襄阳}}
for x in range(

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务