1、加载json数据
import json
from country_codes import get_coutry_code
filename = 'population_data.json'
with open(filename) as f:
pop_data = json.load(f)
#打印各个国家2010年的人口数量
for pop_dict in pop_data:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = int(float(pop_dict['Value']))
print(country_name+" "+str(population))
code = get_coutry_code(country_name)
if code:
print(code + ':' + str(population))
else:
print('ERROR-'+country_name)
2、画世界地图
import pygal_maps_world.maps
wm = pygal_maps_world.maps.World()
wm.title = 'North,Central,and South America'
wm.add('North America',['ca','mx','us'])
wm.add('Central America', ['bz', 'cr', 'gt', 'hn', 'ni', 'pa', 'sv'])
wm.add('South America', ['ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf',
'gy', 'pe', 'py', 'sr', 'uy', 've'])
# wm.add('North America',{'ca':34126000,'ux':30934900,'mx':113423000})
wm.render_to_file('na_americas.svg')
