Skip to content

Commit

Permalink
Location: ISO2 codes from WDI (#5)
Browse files Browse the repository at this point in the history
* Add ISO2 code and income level from WDI

* Remove income level from classification
  • Loading branch information
bleonard33 authored and makmanalp committed Nov 28, 2018
1 parent 53ed3e2 commit cdf935a
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 259 deletions.
21 changes: 21 additions & 0 deletions location/International/Atlas/clean.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import pandas as pd
from pandas.io.json import json_normalize
import requests
import json

from classification import (
Hierarchy,
parent_code_table_to_parent_id_table,
Classification,
)


def get_wdi_data():
r = requests.get("http://api.worldbank.org/v2/countries/?format=json&per_page=400")

# Metadata in 0, data in 1
wdi_locations = json_normalize(json.loads(r.text)[1])
wdi_locations = wdi_locations[["id", "iso2Code"]].rename(
columns={"id": "iso3", "iso2Code": "iso2"}
)
return wdi_locations


if __name__ == "__main__":

df = pd.read_csv(
Expand All @@ -26,6 +41,12 @@

df = pd.concat([df, regions]).reset_index(drop=True)

# Merge in data from WDI API
wdi_locations = get_wdi_data()
df = df.merge(wdi_locations, left_on="code", right_on="iso3", how="left").drop(
columns=["iso3"]
)

h = Hierarchy(["region", "country"])
parent_id_table = parent_code_table_to_parent_id_table(df, h)
parent_id_table["name"] = parent_id_table["name_en"]
Expand Down
Loading

0 comments on commit cdf935a

Please sign in to comment.