Created
January 8, 2016 11:40
-
-
Save kjam/49cfaeb420ee01af9429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import agate | |
from print_int_table_issue import * #note: to not throw the other error you'll need to comment out the last line | |
def get_country(country_row): | |
return country_dict.get(country_row['Country / Territory'].lower()) | |
country_dict = {} | |
country_json = json.loads(open('earth-cleaned.json', 'rb').read()) | |
for dct in country_json: | |
country_dict[dct['name']] = dct['parent'] | |
cpi_and_cl = cpi_and_cl.compute([('continent', | |
agate.Formula(text_type, get_country)), ]) | |
grp_by_cont = cpi_and_cl.group_by('continent') | |
grp_by_cont | |
agg = grp_by_cont.aggregate([('cl_mean', agate.Mean('Total (%)')), | |
('cl_max', agate.Max('Total (%)')), | |
('cpi_median', agate.Median('CPI 2013 Score')), | |
('cpi_min', agate.Min('CPI 2013 Score'))]) | |
agg | |
agg.print_table() | |
from decimal import getcontext | |
getcontext().prec = 11 | |
agg.print_table() | |
getcontext().prec = 20 | |
agg.print_table() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment