Skip to content

Commit

Permalink
Add livestock classification for colombia rural.
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Mar 6, 2017
1 parent eb4fdd6 commit bb0cc64
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions product/Datlas/Rural/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is basically HS92, with names generously translated by Ryan.

[here](https://docs.google.com/spreadsheets/d/1yLhTZ6cV6aWLJkJmAQGRIEGKFSEeF_dwMtCA3YagOzI/edit#gid=0)
3 changes: 3 additions & 0 deletions product/Datlas/Rural/Tupfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLEAN = PYTHONPATH=../../../ python2.7 -B clean_livestock.py

: in/* |> $(CLEAN) |> out/livestock.csv out/livestock.dta
34 changes: 34 additions & 0 deletions product/Datlas/Rural/clean_livestock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pandas as pd

from classification import (Hierarchy, repeated_table_to_parent_id_table,
parent_code_table_to_parent_id_table,
Classification)

if __name__ == "__main__":
names = pd.read_table("./in/Livestock - Names.tsv", encoding="utf-8",
dtype={"code": str})

hierarchy = pd.read_table("./in/Livestock - Hierarchy.tsv", encoding="utf-8")
hierarchy.columns = ["level1_code", "level0_code"]

fields = {
"level0": [],
"level1": []
}

h = Hierarchy(["level0", "level1"])
parent_code_table = repeated_table_to_parent_id_table(hierarchy, h, fields)
parent_code_table.code = parent_code_table.code.astype(str)

parent_code_table = parent_code_table.merge(names, on=["code", "level"])

parent_id_table = parent_code_table_to_parent_id_table(parent_code_table, h)
parent_id_table["name"] = parent_id_table.name_en

parent_id_table = parent_id_table[["code", "name", "level", "name_en",
"name_es", "parent_id"]]

c = Classification(parent_id_table, h)

c.to_csv("out/livestock.csv")
c.to_stata("out/livestock.dta")
9 changes: 9 additions & 0 deletions product/Datlas/Rural/in/Livestock - Hierarchy.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
level1 level0
buffalos total
equines total
fisheries total
fishing total
goats total
pigs total
poultry total
sheep total
10 changes: 10 additions & 0 deletions product/Datlas/Rural/in/Livestock - Names.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
code level name_en name_es
total level0 Total Total
buffalos level1 Buffaloes Búfalos
equines level1 Equines Equinos
fisheries level1 Fisheries Fisheries
fishing level1 Fishing Fishing
goats level1 Goats Goats
pigs level1 Pigs Pigs
poultry level1 Poultry Poultry
sheep level1 Sheep Sheep
10 changes: 10 additions & 0 deletions product/Datlas/Rural/out/livestock.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"","code","name","level","name_en","name_es","parent_id"
0,"total","Total","level0","Total","Total",""
1,"buffalos","Buffaloes","level1","Buffaloes","Búfalos",0.0
2,"equines","Equines","level1","Equines","Equinos",0.0
3,"fisheries","Fisheries","level1","Fisheries","Fisheries",0.0
4,"fishing","Fishing","level1","Fishing","Fishing",0.0
5,"goats","Goats","level1","Goats","Goats",0.0
6,"pigs","Pigs","level1","Pigs","Pigs",0.0
7,"poultry","Poultry","level1","Poultry","Poultry",0.0
8,"sheep","Sheep","level1","Sheep","Sheep",0.0
Binary file added product/Datlas/Rural/out/livestock.dta
Binary file not shown.
Binary file added product/Datlas/Rural/raw/livestock_dept.dta
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.68",
version="v0.0.69",
author="Mali Akmanalp <Harvard CID>",
description=("Harvard CID's classification tools."),
url="http://github.com/cid-harvard/classifications/",
Expand All @@ -20,6 +20,7 @@
'industry/ISIC/Colombia_Prosperia/out/industries_colombia_isic_prosperia.csv',
'industry/NAICS/Mexico/out/industries_mexico_scian_2007.csv',
'industry/NAICS/Mexico_datlas/out/industries_mexico_scian_2007_datlas.csv',
'product/Datlas/Rural/out/livestock.csv',
'product/HS/Atlas/out/hs92_atlas.csv',
'product/HS/Mexico_Prospedia/out/products_mexico_prospedia.csv',
'product/HS/Colombia_Prospedia/out/products_colombia_prospedia.csv',
Expand Down

0 comments on commit bb0cc64

Please sign in to comment.