#!/usr/bin/env python # coding: utf-8 # In[29]: import json, pandas as pd, matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') # In[30]: data2a=json.loads(file('data2a.json','r').read()) # In[31]: g={} for i in data2a['cities']: g[i]=data2a['cities'][i]['count'] # In[32]: Fro=json.loads(file('F_ro.json','r').read()) # In[33]: f1={} f3={} for i in Fro: if i['country'] not in f1:f1[i['country']]=0 f1[i['country']]+=i[u'heti j\xe1ratsz\xe1m'] if i['country'] not in f3:f3[i['country']]=0 f3[i['country']]+=i[u'heti j\xe1ratsz\xe1m'] # In[34]: Fhu=json.loads(file('F_hu.json','r').read()) # In[35]: f2={} for i in Fhu: if i['country'] not in f2:f2[i['country']]=0 f2[i['country']]+=i[u'heti j\xe1ratsz\xe1m'] if i['country'] not in f3:f3[i['country']]=0 f3[i['country']]+=i[u'heti j\xe1ratsz\xe1m'] # In[36]: hnames=json.loads(file('hnames.json','r').read()) # In[37]: d=[] for f in f3: if f not in {"India","Hong Kong"}: if f in g: print f, f3[f],g[f] d.append({"country":f,u'heti j\xe1ratsz\xe1m':f3[f],u"diaszpóra":g[f],"hcountry":hnames[f]}) elif f=='Czechia': print f,f3[f],g['Czech Republic'] d.append({"country":f,u'heti j\xe1ratsz\xe1m':f3[f],u"diaszpóra":g['Czech Republic'],"hcountry":hnames['Czech Republic']}) else: print '### ERROR ###',f # In[38]: file("diasp.json",'w').write(json.dumps(d)) # In[39]: d=[] for f in f1: if f not in "India": if f in g: d.append({"country":f,u'heti j\xe1ratsz\xe1m':f1[f],u"diaszpóra":g[f],"hcountry":hnames[f]}) elif f=='Czechia': d.append({"country":f,u'heti j\xe1ratsz\xe1m':f1[f],u"diaszpóra":g['Czech Republic'],"hcountry":hnames['Czech Republic']}) # In[40]: file("diasp_ro.json",'w').write(json.dumps(d)) # In[41]: d=[] for f in f2: if f not in "Hong Kong": if f in g: d.append({"country":f,u'heti j\xe1ratsz\xe1m':f2[f],u"diaszpóra":g[f],"hcountry":hnames[f]}) elif f=='Czechia': d.append({"country":f,u'heti j\xe1ratsz\xe1m':f2[f],u"diaszpóra":g['Czech Republic'],"hcountry":hnames['Czech Republic']}) # In[42]: file("diasp_hu.json",'w').write(json.dumps(d))