报错信息:JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 127027 (char 127026)
个人觉得是json解析部分出现问题
import requests
import json
import pandas as pd
import datetime
from pyecharts.charts import Map
from pyecharts import options as opts
# 腾讯数据接口获取json格式疫情数据
def get_ncp_data():
reponse = requests.get('https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5').json()
data = json.loads(reponse['data'])
return data
# 扁平化中国疫情数据
def flatten_ncp_data():
all = json.loads(get_ncp_data())
# 初始化结果链表
provinces = []
date = all['lastUpdateTime']
# 获取各省份确诊病例
china = all['areaTree'][0]['children'] # 获得中国数据
for province in china:
province_ncp = province['children']
province_ncp = {
'日期': date,
'省份': province['name'],
'累计确认': province['total']['confirm'],
'现存病例':province['total']['nowConfirm']
}
provinces.append(province_ncp)
return provinces
# 渲染可视化地图
def render_map_chart():
provinces = flatten_ncp_data()
df = pd.DataFrame(provinces)
c = (
Map()
.add("累计确诊病例",[list(z) for z in zip(list(df["省份"]), list(df['累计确认']))],
"china",is_map_symbol_show=False)
.set_global_opts(title_opts=opts.TitleOpts(title="中国疫情地图"),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
pieces=[
{"max": 0, "min": 0, "label": "0","color":"#e2ebf4"},
{"max": 9, "min": 0, "label": "0-9","color":"#ffe7b2"},
{"max": 99, "min": 10, "label": "10-99","color":"#ffcea0"},
{"max": 999, "min": 100, "label": "100-999","color":"#ffa577"},
{"max": 4999, "min": 1000, "label": "1000-4999","color":"#CD5C5C"},
{"max": 9999, "min": 5000, "label": "5000-9999","color":"#ff2736"},
{"max": 99999, "min": 10000, "label": "10000-99999","color":"#A52A2A"}
]))
)
return c
map_chart=render_map_chart()
map_chart.render_notebook()