From bb0cc64638f4ed4858b7f42d4cd91733e8f6203a Mon Sep 17 00:00:00 2001 From: Mali Akmanalp Date: Mon, 6 Mar 2017 17:33:16 -0500 Subject: [PATCH] Add livestock classification for colombia rural. --- product/Datlas/Rural/README.md | 3 ++ product/Datlas/Rural/Tupfile | 3 ++ product/Datlas/Rural/clean_livestock.py | 34 ++++++++++++++++++ .../Datlas/Rural/in/Livestock - Hierarchy.tsv | 9 +++++ product/Datlas/Rural/in/Livestock - Names.tsv | 10 ++++++ product/Datlas/Rural/out/livestock.csv | 10 ++++++ product/Datlas/Rural/out/livestock.dta | Bin 0 -> 2156 bytes product/Datlas/Rural/raw/livestock_dept.dta | Bin 0 -> 11796 bytes setup.py | 3 +- 9 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 product/Datlas/Rural/README.md create mode 100644 product/Datlas/Rural/Tupfile create mode 100644 product/Datlas/Rural/clean_livestock.py create mode 100644 product/Datlas/Rural/in/Livestock - Hierarchy.tsv create mode 100644 product/Datlas/Rural/in/Livestock - Names.tsv create mode 100644 product/Datlas/Rural/out/livestock.csv create mode 100644 product/Datlas/Rural/out/livestock.dta create mode 100644 product/Datlas/Rural/raw/livestock_dept.dta diff --git a/product/Datlas/Rural/README.md b/product/Datlas/Rural/README.md new file mode 100644 index 0000000..96ff5ee --- /dev/null +++ b/product/Datlas/Rural/README.md @@ -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) diff --git a/product/Datlas/Rural/Tupfile b/product/Datlas/Rural/Tupfile new file mode 100644 index 0000000..706d2e7 --- /dev/null +++ b/product/Datlas/Rural/Tupfile @@ -0,0 +1,3 @@ +CLEAN = PYTHONPATH=../../../ python2.7 -B clean_livestock.py + +: in/* |> $(CLEAN) |> out/livestock.csv out/livestock.dta diff --git a/product/Datlas/Rural/clean_livestock.py b/product/Datlas/Rural/clean_livestock.py new file mode 100644 index 0000000..0597e93 --- /dev/null +++ b/product/Datlas/Rural/clean_livestock.py @@ -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") diff --git a/product/Datlas/Rural/in/Livestock - Hierarchy.tsv b/product/Datlas/Rural/in/Livestock - Hierarchy.tsv new file mode 100644 index 0000000..cd3de97 --- /dev/null +++ b/product/Datlas/Rural/in/Livestock - Hierarchy.tsv @@ -0,0 +1,9 @@ +level1 level0 +buffalos total +equines total +fisheries total +fishing total +goats total +pigs total +poultry total +sheep total \ No newline at end of file diff --git a/product/Datlas/Rural/in/Livestock - Names.tsv b/product/Datlas/Rural/in/Livestock - Names.tsv new file mode 100644 index 0000000..a10c47d --- /dev/null +++ b/product/Datlas/Rural/in/Livestock - Names.tsv @@ -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 \ No newline at end of file diff --git a/product/Datlas/Rural/out/livestock.csv b/product/Datlas/Rural/out/livestock.csv new file mode 100644 index 0000000..0797f5d --- /dev/null +++ b/product/Datlas/Rural/out/livestock.csv @@ -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 diff --git a/product/Datlas/Rural/out/livestock.dta b/product/Datlas/Rural/out/livestock.dta new file mode 100644 index 0000000000000000000000000000000000000000..dfb1c88004e658ed8ba558c10a53247328e337bd GIT binary patch literal 2156 zcmeH{!3u&v5QeuPsJHOaU5%1D2GuDL>K+nPPsc$XVaMSL+`;P#dj7xw!ki?}0LpB5_F%v3 zq0aE=0rQl4zzo&G!>Ots)}1sF7=QZ>%>(L2-rltnXeaQ83GCA#pj;|4F9fJpk>8L+ zCX{c>FSw*kfL=-qTG$`3H_4NC=N)QK&*|?E9y9sO zUB37JmiJ~tsdO|Qt*%Q)!=bUUXk9EB4kcrWSTq$22ZLpyg02^#nkng6Q&IzGpFb>A z(DO1>8SX`)g354cMEK;r2>%@s4ke;Bu|ydEH~$Hx;|(#mYG@808Yl`3i`4{*3WH^V zVCleMd8nZ0uc3mjC>o;8Vd61|uYF)%k3oF>7hjLbGw=7?+g!Kvbx|+#`iA|?_1#m= zbsJxM4=}I$@HJGRy@n=5lksRxB37NA(i}^L^JstCmv(mU>|gVNTADjYk531k=8U%nnNN2NGVdQ`nd_H>=ofro zK%ow4Pd&^%q2fRMK&YTAeUvycF;?yLakbHIcNtO#esx?IEpqG! z`j43vrf^Lso#7NTOXBNGGRYH_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