In [1]:
import pandas as pd
import json
In [2]:
df = pd.read_csv('https://raw.githubusercontent.com/vincentarelbundock/countrycode/master/data/countrycode_data.csv')
df.head()
Out[2]:
In [3]:
df = df.dropna(subset=['iso3c'])
In [4]:
outfile = 'get-iso3.json'
out = []
for iso3, regex in zip(df['iso3c'], df['regex']):
out.append(dict(iso3=iso3, regex=regex))
with open(outfile, 'w') as f:
json.dump(out, f, separators=(',',':'))
In [5]:
outfile = 'country-name_to_iso3.json'
out = dict()
for iso3, regex in zip(df['iso3c'], df['regex']):
out[iso3] = regex
with open(outfile, 'w') as f:
json.dump(out, f, separators=(',',':'))
In [6]:
outfile = 'iso3-to-name.json'
out = dict()
for iso3, country_name in zip(df['iso3c'], df['country_name']):
out[iso3] = country_name
with open(outfile, 'w') as f:
json.dump(out, f, separators=(',',':'))