import numpy as np
import pandas as pd
import akshare as ak
import xlrd
from pyecharts import options as opts
from pyecharts.charts import Map
df= ak.covid_19_163(indicator="世界历史累计数据")
df=df.reset_index()
df.columns=['国家','确诊病例','疑似病例','治愈病例','死亡病例','重症病例','输入病例']
country_name = pd.read_excel("世界各国中英文对照.xlsx")
df = pd.merge(df,country_name,left_on='国家',right_on='国家',how='inner')
df.columns=['国家','确诊病例','疑似病例','治愈病例','死亡病例','重症病例','输入病例','英文名称']
df=df.fillna(0)
df['输入病例']=df['输入病例'].astype('int')
print(df)
df.to_excel("cov_df.xlsx")
data=pd.read_excel("cov_df.xlsx")
world_map = Map(init_opts=opts.InitOpts(width="1800px", height="700px",
bg_color="#ADD8E6", page_title="世界疫情地图",theme='white'))
world_map.add("确诊病例",[list(z) for z in zip(data["英文名称"],data["确诊病例"] )],
is_map_symbol_show=False,maptype="world",
label_opts=opts.LabelOpts(is_show=False),
itemstyle_opts=opts.ItemStyleOpts(color="rgb(98,120,140)"))
world_map.set_global_opts(title_opts = opts.TitleOpts(title='全世界新冠确诊人数'),
legend_opts=opts.LegendOpts(is_show=False),
visualmap_opts=opts.VisualMapOpts(max_=10000000, is_piecewise=True,
pieces=[{"max": 10000000, "min": 1000001, "label": ">1000000", "color": "#8A0808"},
{"max": 1000000, "min": 100001, "label": "1000000-100001", "color": "#B40404"},
{"max": 100000, "min": 10001, "label": "100000-10001", "color": "#DF0101"},
{"max": 10000, "min": 1001, "label": "10000-1001", "color": "#F78181"},
{"max": 1000, "min": 100, "label": "1000-100", "color": "#F5A9A9"},
{"max": 100, "min": 0, "label": "<100", "color": "#fababa"},]
)
)
world_map.render('世界新冠疫情地图.html')
结果如下(一些国家与英文名称对应不当,地图里少了些地区)