Skip to content

Commit

Permalink
Add international atlas country codes from COMTRADE.
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Oct 18, 2017
1 parent 3387f49 commit 9d65abe
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 1 deletion.
4 changes: 4 additions & 0 deletions location/International/Atlas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The classification for the international atlas. This is based on the
conventions of the COMTRADE data.

https://docs.google.com/spreadsheets/d/1Kg1-J1C0EYWTTPJA-Cs4fd4AyAJ8AZeCoubpnLfRWn4/edit#gid=0
3 changes: 3 additions & 0 deletions location/International/Atlas/Tupfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLEAN = PYTHONPATH=../../../ python2.7 -B clean.py

: in/* |> $(CLEAN) |> out/locations_international_atlas.csv out/locations_international_atlas.dta
29 changes: 29 additions & 0 deletions location/International/Atlas/clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pandas as pd

from classification import (Hierarchy, parent_code_table_to_parent_id_table,
Classification)

if __name__ == "__main__":

df = pd.read_csv("./in/International Atlas Location Codes - Clean Countries.csv",
encoding="utf-8",
dtype={"parent_code": str}
)\
.drop("comtrade_name", axis=1)
df["level"] = "country"

regions = pd.read_csv("./in/International Atlas Location Codes - Continents and Regions.csv", encoding="utf-8")
regions["name_short_en"] = regions["name_en"]
regions["name_short_es"] = regions["name_es"]
regions["level"] = "region"
regions["code"] = regions["code"].astype(unicode)

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

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"]

c = Classification(parent_id_table, h)
c.to_csv("out/locations_international_atlas.csv")
c.to_stata("out/locations_international_atlas.dta")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
code,name_en,name_es,level,parent_code
1,Africa,África,region,
2,Asia,Asia,region,
3,Oceania,Oceanía,region,
4,Europe,Europa,region,
5,North America,Norteamérica,region,
6,South America,Sudamérica,region,
7,Central America ,Centroamérica,region,
8,Carribean,Caribe,region,
9,Other,Otro,region,
262 changes: 262 additions & 0 deletions location/International/Atlas/out/locations_international_atlas.csv

Large diffs are not rendered by default.

Binary file not shown.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="linnaeus",
version="v0.0.82",
version="v0.0.83",
author="Mali Akmanalp <Harvard CID>",
description=("Harvard CID's classification tools."),
url="http://github.com/cid-harvard/classifications/",
Expand Down Expand Up @@ -45,6 +45,7 @@
'location/International/DANE/out/locations_international_dane.csv',
'location/International/Mexico/out/locations_international_mexico.csv',
'location/International/ISO-CID/out/locations_international_iso_cid.csv',
'location/International/Atlas/out/locations_international_atlas.csv',
]
}
)

0 comments on commit 9d65abe

Please sign in to comment.