代码拉取完成,页面将自动刷新
import json
import pygal.maps.world
from country_code import get_country_code
#将数据加载到一个列表中
filename = 'population.json'
with open(filename) as f:
pop_data = json.load(f)
#创建一个包含人口数量的字典
cc_populations = {}
#打印每个国家2018年的预估人口
for pop_dict in pop_data:
if pop_dict["Year"] == 2015:
country = pop_dict["Country Name"]
population = pop_dict["Value"]
code = get_country_code(country)
if code:
cc_populations[code] = population
print(country+": "+str(population))
print(cc_populations)
#开始绘制世界地图
wm = pygal.maps.world.World()
wm.title = "The World Map Population Of 2016"
wm.add('2016',cc_populations)
wm.render_to_file("world_map.svg")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。