In [21]:
import json, pandas as pd, matplotlib.pyplot as plt
%matplotlib inline
In [22]:
data1a=json.loads(file('data1a.json','r').read())
In [23]:
g={}
for i in data1a['cities']:
    k=i[:i.find('(')]
    g[k]=data1a['cities'][i]['count']
In [24]:
Fro=json.loads(file('F_ro.json','r').read())
In [25]:
f1={}
f3={}
for i in Fro:
    if i['to'] not in f1:f1[i['to']]=0
    f1[i['to']]+=i[u'heti j\xe1ratsz\xe1m']
    if i['to'] not in f3:f3[i['to']]=0
    f3[i['to']]+=i[u'heti j\xe1ratsz\xe1m']
In [26]:
Fhu=json.loads(file('F_hu.json','r').read())
In [27]:
f2={}
for i in Fhu:
    if i['to'] not in f2:f2[i['to']]=0
    f2[i['to']]+=i[u'heti j\xe1ratsz\xe1m']
    if i['to'] not in f3:f3[i['to']]=0
    f3[i['to']]+=i[u'heti j\xe1ratsz\xe1m']
In [28]:
#define locationrenamer 

def namer(s):
    
    if s=='Belgrade': return 'Belgrád'
    elif s=='Budapest': return 'Budapest'
    elif s=='Cluj-Napoca': return 'Kolozsvár'
    elif s=='Timi\xc8\x99oara': return 'Temesvár'
    elif s=='Targu-Mures': return 'Marosvásárhely'
    elif s=='Vienna': return 'Bécs'
    elif s=='Paris': return 'Párizs'
    elif s=='Nagy-V\xc3\xa1rad': return 'Nagyvárad'
    elif s=='Krak\xc3\xb3w': return 'Krakkó'
    elif s=='Sibiu': return 'Nagyszeben'
    elif s=='Bucharest': return 'Bukarest'
    elif s=='Oradea': return 'Nagyvárad'
    elif s=='Brussels': return 'Brüsszel'
    elif s=='Cologne': return 'Köln'
    elif s=='Athens': return 'Athén'
    elif s=='Brasov': return 'Brassó'
    elif s=='Copenhagen': return 'Koppenhága'
    elif s=='Debreczen': return 'Debrecen'
    elif s=='Leipzig': return 'Lipcse'
    elif s=='Munich': return 'München'
    elif s=='Nuremberg': return 'Nüremberg'
    elif s=='Amsterdam': return 'Amszterdam'
    elif s=='Milan': return 'Milánó'
    elif s=='Gyor': return 'Győr'
    elif s=='K\xc3\xb8benhavn': return 'Koppenhága'
    elif s=='Geneva': return 'Genf'
    elif s=='Prague': return 'Prága'
    elif s=='Turin': return 'Torinó'
    elif s=='Rome': return 'Róma'
    elif s=='Nagy-Sz\xc3\xa9ben': return 'Nagyszeben'
    elif s=='Iasi': return 'Jászvásár'
    elif s=='Florence': return 'Firenze'
    elif s=='Warsaw': return u'Varsó'
    elif s=='Kiev': return u'Kijev'
    elif s=='Malmo': return u'Malmö'
    elif s=='Zurich': return u'Zürich'
    elif s=='Beirut': return 'Bejrút'
    elif s=='Riyadh': return 'Rijád'
    elif s=='Jerusalem': return 'Jeruzsálem'
    elif s=='Naples': return 'Nápoly'
    elif s=='Beijing': return 'Peking'
    elif s=='Constanta': return 'Konstanca'
    elif s=='Istanbul': return 'Isztambul'
    elif s=='Corfu': return 'Korfu'
    elif s=='Bratislava': return 'Pozsony'
    elif s=='City of Brussels': return 'Brüsszel'
    elif s=='Dubai': return 'Dubaj'
    elif s=='Timisoara': return u'Temesvár'
    elif s=='Satu Mare': return u'Szatmár'
    elif s=='Sofia': return u'Szófia'
    elif s=='Lisbon': return u'Lisszabon'
    elif s=='Nice': return u'Nizza'
    elif s=='Karlsruhe/Baden-Baden': return u'Karlsruhe'
    elif s=='Moscow': return 'Moszkva'
    
    else: return s
In [29]:
d=[]
for f in f3:
    if f not in {"Hong Kong", "Pune"}:
        if f in g:
            d.append({"city":f,u'heti j\xe1ratsz\xe1m':f3[f],u"diaszpóra":g[f]})
In [30]:
file("diasp_cities.json",'w').write(json.dumps(d))