I'm with the book Python Crash Course and I can not visualize the World population map. When I open the .svg file in Chrome I receive the error of 'No Data'.
I do not receive any errors when I run the program. Printing the cc_populations
dictionary is printed correctly, so the information is actually stored.
Thanks in advance!
The code is as follows:
import json
import pygal
from country_codes import get_country_code
from pygal.maps.world import World
wm = World()
filename = 'population_data.json'
with open(filename) as f:
pop_data = json.load(f)
# Print each country's population
cc_populations = {}
for pop_dict in pop_data:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = int(float((pop_dict['Value'])))
code = get_country_code(country_name)
if code:
cc_populations[code] = population
# Create map
wm.title = 'World population in 2010 per country'
wm.add = ('2010', cc_populations)
wm.render_to_file('world_population.svg')
print(cc_populations)