process json in pygal

来源:互联网 发布:面试常用的排序算法 编辑:程序博客网 时间:2024/06/05 14:27
import jsonfrom random_walk import get_country_codefrom pygal.maps.world import Worldfrom pygal.style import RotateStylefrom pygal.style import LightColorizedStyle#from pygal.style import RotateStyle as RS,LightColorStyle as LCSfilename = 'population_data.json'with open(filename) as f:    pop_data = json.load(f)cc_population={}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_population[code]=populationcc_1,cc_2,cc_3={},{},{}for cc,pop in cc_population.items():    if pop <10000000:        cc_1[cc]=pop    elif pop <1000000000:        cc_2[cc]=pop    else:        cc_3[cc]=popprint(len(cc_1),len(cc_2),len(cc_3))#wm=World()#set the basic color#wm_style = RotateStyle('#336699')#brighten the backgroudcolor#wm_style = LightColorizedStylewm_style = RotateStyle('#336699',base_style=LightColorizedStyle)wm=World(style=wm_style)wm.title = "World population in 2010,by Country"#wm.add('2010',cc_population)#group the datawm.add('0-10m',cc_1)wm.add('10m-1bn',cc_2)wm.add('>1bn',cc_3)wm.render_to_file('World_population.svg')

这里写图片描述

原创粉丝点击