1

Loading a json file to a list, converting to a dictionary in order to load into the pygal worldmap. When I print the dictionary the data looks ok (to me), however the map opens (from an svg file) but with no data plotted.

No traceback errors are occuring.

I'm not running the latest version of pygal.

Sample output from dictionary:

{'AF': 9733784, 'AL': 1437590, 'DZ': 92215683, 'AO': 17394550, 'AG': 19061, 'AR': 0}

Code below:

import json

import pygal

# Load the data into a list.

filename = 'test.json'
with open(filename, 'rb') as f:
    sr_data = json.load(f)

# Print sr_data rows.

sr_exp = {}
for sr_dict in sr_data:
    country_code = sr_dict['CountryCode']
    gross = int(float(sr_dict['Exposed']))
    if country_code:
        sr_exp[country_code] = gross

# Create map.

wm = pygal.Worldmap()
wm.title = 'SR Data'
wm.add('',sr_exp)

wm.render_to_file('sr.svg')
CGarden
  • 169
  • 17

1 Answers1

0

The country codes used as keys in your dictionary need to be in lower case. The simplest fix would be to change the line

sr_exp[country_code] = gross

to

sr_exp[country_code.lower()] = gross
mostlyoxygen
  • 981
  • 5
  • 14