revanth7667 commited on
Commit
6a0acc8
1 Parent(s): 10ce0ea

updated population and created mortality files

Browse files
.01_Data/02_Processed/02_Mortality.parquet ADDED
Binary file (62.3 kB). View file
 
02_Codes/01_population_eda.ipynb CHANGED
@@ -51,78 +51,78 @@
51
  " </thead>\n",
52
  " <tbody>\n",
53
  " <tr>\n",
54
- " <th>13280</th>\n",
55
  " <td>NaN</td>\n",
56
- " <td>Kentucky</td>\n",
57
- " <td>21.0</td>\n",
58
- " <td>Christian County, KY</td>\n",
59
- " <td>21047.0</td>\n",
60
- " <td>2010.0</td>\n",
61
- " <td>2010.0</td>\n",
62
- " <td>74145</td>\n",
63
  " </tr>\n",
64
  " <tr>\n",
65
- " <th>12354</th>\n",
66
  " <td>NaN</td>\n",
67
- " <td>Kansas</td>\n",
68
- " <td>20.0</td>\n",
69
- " <td>Marion County, KS</td>\n",
70
- " <td>20115.0</td>\n",
71
- " <td>2007.0</td>\n",
72
- " <td>2007.0</td>\n",
73
- " <td>12707</td>\n",
74
  " </tr>\n",
75
  " <tr>\n",
76
- " <th>21061</th>\n",
77
  " <td>NaN</td>\n",
78
- " <td>Montana</td>\n",
79
- " <td>30.0</td>\n",
80
- " <td>Glacier County, MT</td>\n",
81
- " <td>30035.0</td>\n",
82
- " <td>2004.0</td>\n",
83
- " <td>2004.0</td>\n",
84
- " <td>13388</td>\n",
85
  " </tr>\n",
86
  " <tr>\n",
87
- " <th>5447</th>\n",
88
  " <td>NaN</td>\n",
89
- " <td>Georgia</td>\n",
90
- " <td>13.0</td>\n",
91
- " <td>Cherokee County, GA</td>\n",
92
- " <td>13057.0</td>\n",
93
- " <td>2003.0</td>\n",
94
- " <td>2003.0</td>\n",
95
- " <td>165585</td>\n",
96
  " </tr>\n",
97
  " <tr>\n",
98
- " <th>17285</th>\n",
99
  " <td>NaN</td>\n",
100
- " <td>Minnesota</td>\n",
101
- " <td>27.0</td>\n",
102
- " <td>Cass County, MN</td>\n",
103
- " <td>27021.0</td>\n",
104
- " <td>2011.0</td>\n",
105
- " <td>2011.0</td>\n",
106
- " <td>28383</td>\n",
107
  " </tr>\n",
108
  " </tbody>\n",
109
  "</table>\n",
110
  "</div>"
111
  ],
112
  "text/plain": [
113
- " Notes State State Code County County Code \\\n",
114
- "13280 NaN Kentucky 21.0 Christian County, KY 21047.0 \n",
115
- "12354 NaN Kansas 20.0 Marion County, KS 20115.0 \n",
116
- "21061 NaN Montana 30.0 Glacier County, MT 30035.0 \n",
117
- "5447 NaN Georgia 13.0 Cherokee County, GA 13057.0 \n",
118
- "17285 NaN Minnesota 27.0 Cass County, MN 27021.0 \n",
119
  "\n",
120
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
121
- "13280 2010.0 2010.0 74145 \n",
122
- "12354 2007.0 2007.0 12707 \n",
123
- "21061 2004.0 2004.0 13388 \n",
124
- "5447 2003.0 2003.0 165585 \n",
125
- "17285 2011.0 2011.0 28383 "
126
  ]
127
  },
128
  "execution_count": 2,
@@ -132,7 +132,7 @@
132
  ],
133
  "source": [
134
  "# Load Raw Data File\n",
135
- "df = pd.read_csv(\"../01_Data/01_Raw/raw_population.txt\", sep=\"\\t\")\n",
136
  "df.sample(5)"
137
  ]
138
  },
@@ -450,73 +450,73 @@
450
  " </thead>\n",
451
  " <tbody>\n",
452
  " <tr>\n",
453
- " <th>22685</th>\n",
454
- " <td>Nebraska</td>\n",
455
- " <td>31.0</td>\n",
456
- " <td>Thurston County, NE</td>\n",
457
- " <td>31173.0</td>\n",
458
- " <td>2003.0</td>\n",
459
- " <td>2003.0</td>\n",
460
- " <td>6987</td>\n",
461
- " </tr>\n",
462
- " <tr>\n",
463
- " <th>39888</th>\n",
464
- " <td>Wisconsin</td>\n",
465
- " <td>55.0</td>\n",
466
- " <td>Door County, WI</td>\n",
467
- " <td>55029.0</td>\n",
468
- " <td>2007.0</td>\n",
469
- " <td>2007.0</td>\n",
470
- " <td>27957</td>\n",
471
- " </tr>\n",
472
- " <tr>\n",
473
- " <th>4159</th>\n",
474
- " <td>Connecticut</td>\n",
475
- " <td>9.0</td>\n",
476
- " <td>Tolland County, CT</td>\n",
477
- " <td>9013.0</td>\n",
478
  " <td>2015.0</td>\n",
479
  " <td>2015.0</td>\n",
480
- " <td>151815</td>\n",
481
  " </tr>\n",
482
  " <tr>\n",
483
- " <th>20889</th>\n",
484
- " <td>Montana</td>\n",
485
- " <td>30.0</td>\n",
486
- " <td>Broadwater County, MT</td>\n",
487
- " <td>30007.0</td>\n",
488
- " <td>2014.0</td>\n",
489
- " <td>2014.0</td>\n",
490
- " <td>5657</td>\n",
491
  " </tr>\n",
492
  " <tr>\n",
493
- " <th>36855</th>\n",
494
- " <td>Virginia</td>\n",
495
- " <td>51.0</td>\n",
496
- " <td>Bland County, VA</td>\n",
497
- " <td>51021.0</td>\n",
498
- " <td>2003.0</td>\n",
499
- " <td>2003.0</td>\n",
500
- " <td>6913</td>\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  " </tr>\n",
502
  " </tbody>\n",
503
  "</table>\n",
504
  "</div>"
505
  ],
506
  "text/plain": [
507
- " State State Code County County Code \\\n",
508
- "22685 Nebraska 31.0 Thurston County, NE 31173.0 \n",
509
- "39888 Wisconsin 55.0 Door County, WI 55029.0 \n",
510
- "4159 Connecticut 9.0 Tolland County, CT 9013.0 \n",
511
- "20889 Montana 30.0 Broadwater County, MT 30007.0 \n",
512
- "36855 Virginia 51.0 Bland County, VA 51021.0 \n",
513
  "\n",
514
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
515
- "22685 2003.0 2003.0 6987 \n",
516
- "39888 2007.0 2007.0 27957 \n",
517
- "4159 2015.0 2015.0 151815 \n",
518
- "20889 2014.0 2014.0 5657 \n",
519
- "36855 2003.0 2003.0 6913 "
520
  ]
521
  },
522
  "execution_count": 8,
@@ -640,73 +640,73 @@
640
  " </thead>\n",
641
  " <tbody>\n",
642
  " <tr>\n",
643
- " <th>9811</th>\n",
644
- " <td>Indiana</td>\n",
645
- " <td>18</td>\n",
646
- " <td>Monroe County, IN</td>\n",
647
- " <td>18105</td>\n",
648
- " <td>2012</td>\n",
649
- " <td>2012.0</td>\n",
650
- " <td>141570</td>\n",
651
  " </tr>\n",
652
  " <tr>\n",
653
- " <th>30855</th>\n",
654
- " <td>South Dakota</td>\n",
655
- " <td>46</td>\n",
656
- " <td>Brule County, SD</td>\n",
657
- " <td>46015</td>\n",
658
- " <td>2009</td>\n",
659
- " <td>2009.0</td>\n",
660
- " <td>5184</td>\n",
661
  " </tr>\n",
662
  " <tr>\n",
663
- " <th>38764</th>\n",
664
- " <td>Washington</td>\n",
665
- " <td>53</td>\n",
666
- " <td>Lincoln County, WA</td>\n",
667
- " <td>53043</td>\n",
668
- " <td>2014</td>\n",
669
- " <td>2014.0</td>\n",
670
- " <td>10224</td>\n",
671
  " </tr>\n",
672
  " <tr>\n",
673
- " <th>34257</th>\n",
674
- " <td>Texas</td>\n",
675
- " <td>48</td>\n",
676
- " <td>Hidalgo County, TX</td>\n",
677
- " <td>48215</td>\n",
678
- " <td>2005</td>\n",
679
- " <td>2005.0</td>\n",
680
- " <td>674982</td>\n",
681
  " </tr>\n",
682
  " <tr>\n",
683
- " <th>14148</th>\n",
684
- " <td>Kentucky</td>\n",
685
- " <td>21</td>\n",
686
- " <td>Nicholas County, KY</td>\n",
687
- " <td>21181</td>\n",
688
- " <td>2007</td>\n",
689
- " <td>2007.0</td>\n",
690
- " <td>7143</td>\n",
691
  " </tr>\n",
692
  " </tbody>\n",
693
  "</table>\n",
694
  "</div>"
695
  ],
696
  "text/plain": [
697
- " State State Code County County Code \\\n",
698
- "9811 Indiana 18 Monroe County, IN 18105 \n",
699
- "30855 South Dakota 46 Brule County, SD 46015 \n",
700
- "38764 Washington 53 Lincoln County, WA 53043 \n",
701
- "34257 Texas 48 Hidalgo County, TX 48215 \n",
702
- "14148 Kentucky 21 Nicholas County, KY 21181 \n",
703
  "\n",
704
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
705
- "9811 2012 2012.0 141570 \n",
706
- "30855 2009 2009.0 5184 \n",
707
- "38764 2014 2014.0 10224 \n",
708
- "34257 2005 2005.0 674982 \n",
709
- "14148 2007 2007.0 7143 "
710
  ]
711
  },
712
  "execution_count": 12,
@@ -814,68 +814,61 @@
814
  " </thead>\n",
815
  " <tbody>\n",
816
  " <tr>\n",
817
- " <th>14210</th>\n",
818
- " <td>Kentucky</td>\n",
819
- " <td>21</td>\n",
820
- " <td>Pendleton County, KY</td>\n",
821
- " <td>21191</td>\n",
822
- " <td>2004</td>\n",
823
- " <td>14809</td>\n",
824
  " </tr>\n",
825
  " <tr>\n",
826
- " <th>30045</th>\n",
827
- " <td>Pennsylvania</td>\n",
828
- " <td>42</td>\n",
829
- " <td>Washington County, PA</td>\n",
830
- " <td>42125</td>\n",
831
- " <td>2005</td>\n",
832
- " <td>205359</td>\n",
 
 
 
 
 
 
 
 
 
833
  " </tr>\n",
834
  " <tr>\n",
835
- " <th>31810</th>\n",
836
  " <td>Tennessee</td>\n",
837
  " <td>47</td>\n",
838
  " <td>Clay County, TN</td>\n",
839
  " <td>47027</td>\n",
840
- " <td>2015</td>\n",
841
- " <td>7668</td>\n",
842
- " </tr>\n",
843
- " <tr>\n",
844
- " <th>25762</th>\n",
845
- " <td>North Carolina</td>\n",
846
- " <td>37</td>\n",
847
- " <td>Swain County, NC</td>\n",
848
- " <td>37173</td>\n",
849
- " <td>2012</td>\n",
850
- " <td>14054</td>\n",
851
  " </tr>\n",
852
  " <tr>\n",
853
- " <th>20357</th>\n",
854
- " <td>Missouri</td>\n",
855
- " <td>29</td>\n",
856
- " <td>Pemiscot County, MO</td>\n",
857
- " <td>29155</td>\n",
858
  " <td>2015</td>\n",
859
- " <td>17427</td>\n",
860
  " </tr>\n",
861
  " </tbody>\n",
862
  "</table>\n",
863
  "</div>"
864
  ],
865
  "text/plain": [
866
- " State State_Code County County_Code Year \\\n",
867
- "14210 Kentucky 21 Pendleton County, KY 21191 2004 \n",
868
- "30045 Pennsylvania 42 Washington County, PA 42125 2005 \n",
869
- "31810 Tennessee 47 Clay County, TN 47027 2015 \n",
870
- "25762 North Carolina 37 Swain County, NC 37173 2012 \n",
871
- "20357 Missouri 29 Pemiscot County, MO 29155 2015 \n",
872
- "\n",
873
- " Population \n",
874
- "14210 14809 \n",
875
- "30045 205359 \n",
876
- "31810 7668 \n",
877
- "25762 14054 \n",
878
- "20357 17427 "
879
  ]
880
  },
881
  "execution_count": 15,
@@ -920,34 +913,34 @@
920
  " </thead>\n",
921
  " <tbody>\n",
922
  " <tr>\n",
923
- " <th>1937</th>\n",
924
- " <td>JONES</td>\n",
925
- " <td>NC</td>\n",
926
- " <td>37103</td>\n",
927
  " </tr>\n",
928
  " <tr>\n",
929
- " <th>3083</th>\n",
930
- " <td>MARQUETTE</td>\n",
931
- " <td>WI</td>\n",
932
- " <td>55077</td>\n",
933
  " </tr>\n",
934
  " <tr>\n",
935
- " <th>564</th>\n",
936
- " <td>CLEARWATER</td>\n",
937
- " <td>ID</td>\n",
938
- " <td>16035</td>\n",
939
  " </tr>\n",
940
  " <tr>\n",
941
- " <th>722</th>\n",
942
- " <td>HANCOCK</td>\n",
943
- " <td>IN</td>\n",
944
- " <td>18059</td>\n",
945
  " </tr>\n",
946
  " <tr>\n",
947
- " <th>1229</th>\n",
948
- " <td>ALLEGAN</td>\n",
949
- " <td>MI</td>\n",
950
- " <td>26005</td>\n",
951
  " </tr>\n",
952
  " </tbody>\n",
953
  "</table>\n",
@@ -955,11 +948,11 @@
955
  ],
956
  "text/plain": [
957
  " BUYER_COUNTY BUYER_STATE countyfips\n",
958
- "1937 JONES NC 37103\n",
959
- "3083 MARQUETTE WI 55077\n",
960
- "564 CLEARWATER ID 16035\n",
961
- "722 HANCOCK IN 18059\n",
962
- "1229 ALLEGAN MI 26005"
963
  ]
964
  },
965
  "execution_count": 16,
@@ -969,7 +962,7 @@
969
  ],
970
  "source": [
971
  "# maps with fips for proper county names\n",
972
- "fips = pd.read_csv(\"../01_Data/01_Raw/county_fips.csv\")\n",
973
  "fips.sample(5)"
974
  ]
975
  },
@@ -1743,68 +1736,68 @@
1743
  " </thead>\n",
1744
  " <tbody>\n",
1745
  " <tr>\n",
1746
- " <th>13500</th>\n",
1747
- " <td>Kentucky</td>\n",
1748
- " <td>21</td>\n",
1749
- " <td>McLean County, KY</td>\n",
1750
- " <td>21149</td>\n",
1751
- " <td>2009</td>\n",
1752
- " <td>9566</td>\n",
1753
- " <td>MCLEAN</td>\n",
1754
- " <td>KY</td>\n",
1755
- " <td>21149</td>\n",
1756
  " <td>both</td>\n",
1757
  " </tr>\n",
1758
  " <tr>\n",
1759
- " <th>28137</th>\n",
1760
- " <td>Oklahoma</td>\n",
1761
- " <td>40</td>\n",
1762
- " <td>Pottawatomie County, OK</td>\n",
1763
- " <td>40125</td>\n",
1764
- " <td>2008</td>\n",
1765
- " <td>68752</td>\n",
1766
- " <td>POTTAWATOMIE</td>\n",
1767
- " <td>OK</td>\n",
1768
- " <td>40125</td>\n",
1769
  " <td>both</td>\n",
1770
  " </tr>\n",
1771
  " <tr>\n",
1772
- " <th>26396</th>\n",
1773
- " <td>Ohio</td>\n",
1774
- " <td>39</td>\n",
1775
- " <td>Crawford County, OH</td>\n",
1776
- " <td>39033</td>\n",
1777
- " <td>2009</td>\n",
1778
- " <td>43921</td>\n",
1779
- " <td>CRAWFORD</td>\n",
1780
- " <td>OH</td>\n",
1781
- " <td>39033</td>\n",
1782
  " <td>both</td>\n",
1783
  " </tr>\n",
1784
  " <tr>\n",
1785
- " <th>26602</th>\n",
1786
- " <td>Ohio</td>\n",
1787
- " <td>39</td>\n",
1788
- " <td>Hardin County, OH</td>\n",
1789
- " <td>39065</td>\n",
1790
  " <td>2007</td>\n",
1791
- " <td>32132</td>\n",
1792
- " <td>HARDIN</td>\n",
1793
- " <td>OH</td>\n",
1794
- " <td>39065</td>\n",
1795
  " <td>both</td>\n",
1796
  " </tr>\n",
1797
  " <tr>\n",
1798
- " <th>20230</th>\n",
1799
- " <td>Missouri</td>\n",
1800
- " <td>29</td>\n",
1801
- " <td>Stoddard County, MO</td>\n",
1802
- " <td>29207</td>\n",
1803
- " <td>2005</td>\n",
1804
- " <td>30240</td>\n",
1805
- " <td>STODDARD</td>\n",
1806
- " <td>MO</td>\n",
1807
- " <td>29207</td>\n",
1808
  " <td>both</td>\n",
1809
  " </tr>\n",
1810
  " </tbody>\n",
@@ -1812,19 +1805,19 @@
1812
  "</div>"
1813
  ],
1814
  "text/plain": [
1815
- " State State_Code County County_Code Year \\\n",
1816
- "13500 Kentucky 21 McLean County, KY 21149 2009 \n",
1817
- "28137 Oklahoma 40 Pottawatomie County, OK 40125 2008 \n",
1818
- "26396 Ohio 39 Crawford County, OH 39033 2009 \n",
1819
- "26602 Ohio 39 Hardin County, OH 39065 2007 \n",
1820
- "20230 Missouri 29 Stoddard County, MO 29207 2005 \n",
1821
  "\n",
1822
- " Population BUYER_COUNTY BUYER_STATE countyfips _merge \n",
1823
- "13500 9566 MCLEAN KY 21149 both \n",
1824
- "28137 68752 POTTAWATOMIE OK 40125 both \n",
1825
- "26396 43921 CRAWFORD OH 39033 both \n",
1826
- "26602 32132 HARDIN OH 39065 both \n",
1827
- "20230 30240 STODDARD MO 29207 both "
1828
  ]
1829
  },
1830
  "execution_count": 23,
@@ -1903,46 +1896,46 @@
1903
  " </thead>\n",
1904
  " <tbody>\n",
1905
  " <tr>\n",
1906
- " <th>23</th>\n",
1907
- " <td>Minnesota</td>\n",
1908
- " <td>Minn.</td>\n",
1909
- " <td>MN</td>\n",
1910
  " </tr>\n",
1911
  " <tr>\n",
1912
- " <th>30</th>\n",
1913
- " <td>New Jersey</td>\n",
1914
- " <td>N.J.</td>\n",
1915
- " <td>NJ</td>\n",
1916
  " </tr>\n",
1917
  " <tr>\n",
1918
- " <th>3</th>\n",
1919
- " <td>Arkansas</td>\n",
1920
- " <td>Ark.</td>\n",
1921
- " <td>AR</td>\n",
1922
  " </tr>\n",
1923
  " <tr>\n",
1924
- " <th>28</th>\n",
1925
- " <td>Nevada</td>\n",
1926
- " <td>Nev.</td>\n",
1927
- " <td>NV</td>\n",
1928
  " </tr>\n",
1929
  " <tr>\n",
1930
- " <th>18</th>\n",
1931
- " <td>Louisiana</td>\n",
1932
- " <td>La.</td>\n",
1933
- " <td>LA</td>\n",
1934
  " </tr>\n",
1935
  " </tbody>\n",
1936
  "</table>\n",
1937
  "</div>"
1938
  ],
1939
  "text/plain": [
1940
- " state abbrev code\n",
1941
- "23 Minnesota Minn. MN\n",
1942
- "30 New Jersey N.J. NJ\n",
1943
- "3 Arkansas Ark. AR\n",
1944
- "28 Nevada Nev. NV\n",
1945
- "18 Louisiana La. LA"
1946
  ]
1947
  },
1948
  "execution_count": 25,
@@ -1951,7 +1944,7 @@
1951
  }
1952
  ],
1953
  "source": [
1954
- "abbreviations = pd.read_csv(\"../01_Data/01_Raw/state_abbreviations.csv\")\n",
1955
  "abbreviations.sample(5)"
1956
  ]
1957
  },
@@ -2006,61 +1999,61 @@
2006
  " </thead>\n",
2007
  " <tbody>\n",
2008
  " <tr>\n",
2009
- " <th>33041</th>\n",
2010
- " <td>Texas</td>\n",
2011
- " <td>CONCHO</td>\n",
2012
- " <td>48095</td>\n",
2013
  " <td>2011</td>\n",
2014
- " <td>4121</td>\n",
2015
- " <td>TX</td>\n",
2016
  " </tr>\n",
2017
  " <tr>\n",
2018
- " <th>9306</th>\n",
2019
- " <td>Indiana</td>\n",
2020
- " <td>MADISON</td>\n",
2021
- " <td>18095</td>\n",
2022
- " <td>2014</td>\n",
2023
- " <td>129773</td>\n",
2024
- " <td>IN</td>\n",
2025
  " </tr>\n",
2026
  " <tr>\n",
2027
- " <th>27074</th>\n",
2028
- " <td>Ohio</td>\n",
2029
- " <td>PUTNAM</td>\n",
2030
- " <td>39137</td>\n",
2031
  " <td>2011</td>\n",
2032
- " <td>34386</td>\n",
2033
- " <td>OH</td>\n",
2034
  " </tr>\n",
2035
  " <tr>\n",
2036
- " <th>39655</th>\n",
2037
- " <td>Wisconsin</td>\n",
2038
- " <td>KEWAUNEE</td>\n",
2039
- " <td>55061</td>\n",
2040
- " <td>2008</td>\n",
2041
- " <td>20636</td>\n",
2042
- " <td>WI</td>\n",
2043
  " </tr>\n",
2044
  " <tr>\n",
2045
- " <th>28895</th>\n",
2046
- " <td>Pennsylvania</td>\n",
2047
- " <td>BRADFORD</td>\n",
2048
- " <td>42015</td>\n",
2049
- " <td>2012</td>\n",
2050
- " <td>63005</td>\n",
2051
- " <td>PA</td>\n",
2052
  " </tr>\n",
2053
  " </tbody>\n",
2054
  "</table>\n",
2055
  "</div>"
2056
  ],
2057
  "text/plain": [
2058
- " State BUYER_COUNTY County_Code Year Population State_Code\n",
2059
- "33041 Texas CONCHO 48095 2011 4121 TX\n",
2060
- "9306 Indiana MADISON 18095 2014 129773 IN\n",
2061
- "27074 Ohio PUTNAM 39137 2011 34386 OH\n",
2062
- "39655 Wisconsin KEWAUNEE 55061 2008 20636 WI\n",
2063
- "28895 Pennsylvania BRADFORD 42015 2012 63005 PA"
2064
  ]
2065
  },
2066
  "execution_count": 27,
@@ -2117,61 +2110,61 @@
2117
  " </thead>\n",
2118
  " <tbody>\n",
2119
  " <tr>\n",
2120
- " <th>38099</th>\n",
2121
- " <td>Washington</td>\n",
2122
- " <td>WA</td>\n",
2123
- " <td>CLALLAM</td>\n",
2124
- " <td>53009</td>\n",
2125
- " <td>2012</td>\n",
2126
- " <td>71791</td>\n",
2127
  " </tr>\n",
2128
  " <tr>\n",
2129
- " <th>31623</th>\n",
2130
  " <td>Tennessee</td>\n",
2131
  " <td>TN</td>\n",
2132
- " <td>HANCOCK</td>\n",
2133
- " <td>47067</td>\n",
2134
- " <td>2010</td>\n",
2135
- " <td>6796</td>\n",
2136
  " </tr>\n",
2137
  " <tr>\n",
2138
- " <th>19983</th>\n",
2139
- " <td>Missouri</td>\n",
2140
- " <td>MO</td>\n",
2141
- " <td>POLK</td>\n",
2142
- " <td>29167</td>\n",
2143
- " <td>2005</td>\n",
2144
- " <td>29308</td>\n",
2145
  " </tr>\n",
2146
  " <tr>\n",
2147
- " <th>33149</th>\n",
2148
- " <td>Texas</td>\n",
2149
- " <td>TX</td>\n",
2150
- " <td>DALLAM</td>\n",
2151
- " <td>48111</td>\n",
2152
- " <td>2015</td>\n",
2153
- " <td>7301</td>\n",
2154
  " </tr>\n",
2155
  " <tr>\n",
2156
- " <th>12855</th>\n",
2157
- " <td>Kentucky</td>\n",
2158
- " <td>KY</td>\n",
2159
- " <td>CLARK</td>\n",
2160
- " <td>21049</td>\n",
2161
- " <td>2014</td>\n",
2162
- " <td>35643</td>\n",
2163
  " </tr>\n",
2164
  " </tbody>\n",
2165
  "</table>\n",
2166
  "</div>"
2167
  ],
2168
  "text/plain": [
2169
- " State State_Code County County_Code Year Population\n",
2170
- "38099 Washington WA CLALLAM 53009 2012 71791\n",
2171
- "31623 Tennessee TN HANCOCK 47067 2010 6796\n",
2172
- "19983 Missouri MO POLK 29167 2005 29308\n",
2173
- "33149 Texas TX DALLAM 48111 2015 7301\n",
2174
- "12855 Kentucky KY CLARK 21049 2014 35643"
2175
  ]
2176
  },
2177
  "execution_count": 28,
@@ -2230,13 +2223,6 @@
2230
  "source": [
2231
  "df5.info()"
2232
  ]
2233
- },
2234
- {
2235
- "cell_type": "code",
2236
- "execution_count": null,
2237
- "metadata": {},
2238
- "outputs": [],
2239
- "source": []
2240
  }
2241
  ],
2242
  "metadata": {
 
51
  " </thead>\n",
52
  " <tbody>\n",
53
  " <tr>\n",
54
+ " <th>20844</th>\n",
55
  " <td>NaN</td>\n",
56
+ " <td>Montana</td>\n",
57
+ " <td>30.0</td>\n",
58
+ " <td>Beaverhead County, MT</td>\n",
59
+ " <td>30001.0</td>\n",
60
+ " <td>2008.0</td>\n",
61
+ " <td>2008.0</td>\n",
62
+ " <td>9166</td>\n",
63
  " </tr>\n",
64
  " <tr>\n",
65
+ " <th>419</th>\n",
66
  " <td>NaN</td>\n",
67
+ " <td>Alabama</td>\n",
68
+ " <td>1.0</td>\n",
69
+ " <td>Hale County, AL</td>\n",
70
+ " <td>1065.0</td>\n",
71
+ " <td>2006.0</td>\n",
72
+ " <td>2006.0</td>\n",
73
+ " <td>16427</td>\n",
74
  " </tr>\n",
75
  " <tr>\n",
76
+ " <th>14805</th>\n",
77
  " <td>NaN</td>\n",
78
+ " <td>Louisiana</td>\n",
79
+ " <td>22.0</td>\n",
80
+ " <td>Franklin Parish, LA</td>\n",
81
+ " <td>22041.0</td>\n",
82
+ " <td>2014.0</td>\n",
83
+ " <td>2014.0</td>\n",
84
+ " <td>20441</td>\n",
85
  " </tr>\n",
86
  " <tr>\n",
87
+ " <th>1416</th>\n",
88
  " <td>NaN</td>\n",
89
+ " <td>Arizona</td>\n",
90
+ " <td>4.0</td>\n",
91
+ " <td>Maricopa County, AZ</td>\n",
92
+ " <td>4013.0</td>\n",
93
+ " <td>2015.0</td>\n",
94
+ " <td>2015.0</td>\n",
95
+ " <td>4174423</td>\n",
96
  " </tr>\n",
97
  " <tr>\n",
98
+ " <th>8090</th>\n",
99
  " <td>NaN</td>\n",
100
+ " <td>Illinois</td>\n",
101
+ " <td>17.0</td>\n",
102
+ " <td>Edgar County, IL</td>\n",
103
+ " <td>17045.0</td>\n",
104
+ " <td>2007.0</td>\n",
105
+ " <td>2007.0</td>\n",
106
+ " <td>18929</td>\n",
107
  " </tr>\n",
108
  " </tbody>\n",
109
  "</table>\n",
110
  "</div>"
111
  ],
112
  "text/plain": [
113
+ " Notes State State Code County County Code \\\n",
114
+ "20844 NaN Montana 30.0 Beaverhead County, MT 30001.0 \n",
115
+ "419 NaN Alabama 1.0 Hale County, AL 1065.0 \n",
116
+ "14805 NaN Louisiana 22.0 Franklin Parish, LA 22041.0 \n",
117
+ "1416 NaN Arizona 4.0 Maricopa County, AZ 4013.0 \n",
118
+ "8090 NaN Illinois 17.0 Edgar County, IL 17045.0 \n",
119
  "\n",
120
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
121
+ "20844 2008.0 2008.0 9166 \n",
122
+ "419 2006.0 2006.0 16427 \n",
123
+ "14805 2014.0 2014.0 20441 \n",
124
+ "1416 2015.0 2015.0 4174423 \n",
125
+ "8090 2007.0 2007.0 18929 "
126
  ]
127
  },
128
  "execution_count": 2,
 
132
  ],
133
  "source": [
134
  "# Load Raw Data File\n",
135
+ "df = pd.read_csv(\"../.01_Data/01_Raw/raw_population.txt\", sep=\"\\t\")\n",
136
  "df.sample(5)"
137
  ]
138
  },
 
450
  " </thead>\n",
451
  " <tbody>\n",
452
  " <tr>\n",
453
+ " <th>28339</th>\n",
454
+ " <td>Oklahoma</td>\n",
455
+ " <td>40.0</td>\n",
456
+ " <td>McClain County, OK</td>\n",
457
+ " <td>40087.0</td>\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
  " <td>2015.0</td>\n",
459
  " <td>2015.0</td>\n",
460
+ " <td>37981</td>\n",
461
  " </tr>\n",
462
  " <tr>\n",
463
+ " <th>23032</th>\n",
464
+ " <td>New Hampshire</td>\n",
465
+ " <td>33.0</td>\n",
466
+ " <td>Cheshire County, NH</td>\n",
467
+ " <td>33005.0</td>\n",
468
+ " <td>2012.0</td>\n",
469
+ " <td>2012.0</td>\n",
470
+ " <td>76957</td>\n",
471
  " </tr>\n",
472
  " <tr>\n",
473
+ " <th>13840</th>\n",
474
+ " <td>Kentucky</td>\n",
475
+ " <td>21.0</td>\n",
476
+ " <td>Letcher County, KY</td>\n",
477
+ " <td>21133.0</td>\n",
478
+ " <td>2011.0</td>\n",
479
+ " <td>2011.0</td>\n",
480
+ " <td>24375</td>\n",
481
+ " </tr>\n",
482
+ " <tr>\n",
483
+ " <th>8898</th>\n",
484
+ " <td>Illinois</td>\n",
485
+ " <td>17.0</td>\n",
486
+ " <td>Schuyler County, IL</td>\n",
487
+ " <td>17169.0</td>\n",
488
+ " <td>2009.0</td>\n",
489
+ " <td>2009.0</td>\n",
490
+ " <td>7489</td>\n",
491
+ " </tr>\n",
492
+ " <tr>\n",
493
+ " <th>18087</th>\n",
494
+ " <td>Minnesota</td>\n",
495
+ " <td>27.0</td>\n",
496
+ " <td>Stearns County, MN</td>\n",
497
+ " <td>27145.0</td>\n",
498
+ " <td>2007.0</td>\n",
499
+ " <td>2007.0</td>\n",
500
+ " <td>146591</td>\n",
501
  " </tr>\n",
502
  " </tbody>\n",
503
  "</table>\n",
504
  "</div>"
505
  ],
506
  "text/plain": [
507
+ " State State Code County County Code \\\n",
508
+ "28339 Oklahoma 40.0 McClain County, OK 40087.0 \n",
509
+ "23032 New Hampshire 33.0 Cheshire County, NH 33005.0 \n",
510
+ "13840 Kentucky 21.0 Letcher County, KY 21133.0 \n",
511
+ "8898 Illinois 17.0 Schuyler County, IL 17169.0 \n",
512
+ "18087 Minnesota 27.0 Stearns County, MN 27145.0 \n",
513
  "\n",
514
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
515
+ "28339 2015.0 2015.0 37981 \n",
516
+ "23032 2012.0 2012.0 76957 \n",
517
+ "13840 2011.0 2011.0 24375 \n",
518
+ "8898 2009.0 2009.0 7489 \n",
519
+ "18087 2007.0 2007.0 146591 "
520
  ]
521
  },
522
  "execution_count": 8,
 
640
  " </thead>\n",
641
  " <tbody>\n",
642
  " <tr>\n",
643
+ " <th>3169</th>\n",
644
+ " <td>California</td>\n",
645
+ " <td>06</td>\n",
646
+ " <td>Trinity County, CA</td>\n",
647
+ " <td>06105</td>\n",
648
+ " <td>2013</td>\n",
649
+ " <td>2013.0</td>\n",
650
+ " <td>13427</td>\n",
651
  " </tr>\n",
652
  " <tr>\n",
653
+ " <th>13252</th>\n",
654
+ " <td>Kentucky</td>\n",
655
+ " <td>21</td>\n",
656
+ " <td>Carter County, KY</td>\n",
657
+ " <td>21043</td>\n",
658
+ " <td>2008</td>\n",
659
+ " <td>2008.0</td>\n",
660
+ " <td>27752</td>\n",
661
  " </tr>\n",
662
  " <tr>\n",
663
+ " <th>39311</th>\n",
664
+ " <td>West Virginia</td>\n",
665
+ " <td>54</td>\n",
666
+ " <td>Marion County, WV</td>\n",
667
+ " <td>54049</td>\n",
668
+ " <td>2015</td>\n",
669
+ " <td>2015.0</td>\n",
670
+ " <td>56815</td>\n",
671
  " </tr>\n",
672
  " <tr>\n",
673
+ " <th>25647</th>\n",
674
+ " <td>North Carolina</td>\n",
675
+ " <td>37</td>\n",
676
+ " <td>Robeson County, NC</td>\n",
677
+ " <td>37155</td>\n",
678
+ " <td>2014</td>\n",
679
+ " <td>2014.0</td>\n",
680
+ " <td>134920</td>\n",
681
  " </tr>\n",
682
  " <tr>\n",
683
+ " <th>16468</th>\n",
684
+ " <td>Michigan</td>\n",
685
+ " <td>26</td>\n",
686
+ " <td>Houghton County, MI</td>\n",
687
+ " <td>26061</td>\n",
688
+ " <td>2013</td>\n",
689
+ " <td>2013.0</td>\n",
690
+ " <td>36691</td>\n",
691
  " </tr>\n",
692
  " </tbody>\n",
693
  "</table>\n",
694
  "</div>"
695
  ],
696
  "text/plain": [
697
+ " State State Code County County Code \\\n",
698
+ "3169 California 06 Trinity County, CA 06105 \n",
699
+ "13252 Kentucky 21 Carter County, KY 21043 \n",
700
+ "39311 West Virginia 54 Marion County, WV 54049 \n",
701
+ "25647 North Carolina 37 Robeson County, NC 37155 \n",
702
+ "16468 Michigan 26 Houghton County, MI 26061 \n",
703
  "\n",
704
  " Yearly July 1st Estimates Yearly July 1st Estimates Code Population \n",
705
+ "3169 2013 2013.0 13427 \n",
706
+ "13252 2008 2008.0 27752 \n",
707
+ "39311 2015 2015.0 56815 \n",
708
+ "25647 2014 2014.0 134920 \n",
709
+ "16468 2013 2013.0 36691 "
710
  ]
711
  },
712
  "execution_count": 12,
 
814
  " </thead>\n",
815
  " <tbody>\n",
816
  " <tr>\n",
817
+ " <th>20737</th>\n",
818
+ " <td>Missouri</td>\n",
819
+ " <td>29</td>\n",
820
+ " <td>Vernon County, MO</td>\n",
821
+ " <td>29217</td>\n",
822
+ " <td>2005</td>\n",
823
+ " <td>20722</td>\n",
824
  " </tr>\n",
825
  " <tr>\n",
826
+ " <th>34648</th>\n",
827
+ " <td>Texas</td>\n",
828
+ " <td>48</td>\n",
829
+ " <td>Knox County, TX</td>\n",
830
+ " <td>48275</td>\n",
831
+ " <td>2006</td>\n",
832
+ " <td>3788</td>\n",
833
+ " </tr>\n",
834
+ " <tr>\n",
835
+ " <th>8311</th>\n",
836
+ " <td>Illinois</td>\n",
837
+ " <td>17</td>\n",
838
+ " <td>Jasper County, IL</td>\n",
839
+ " <td>17079</td>\n",
840
+ " <td>2007</td>\n",
841
+ " <td>9776</td>\n",
842
  " </tr>\n",
843
  " <tr>\n",
844
+ " <th>31809</th>\n",
845
  " <td>Tennessee</td>\n",
846
  " <td>47</td>\n",
847
  " <td>Clay County, TN</td>\n",
848
  " <td>47027</td>\n",
849
+ " <td>2014</td>\n",
850
+ " <td>7626</td>\n",
 
 
 
 
 
 
 
 
 
851
  " </tr>\n",
852
  " <tr>\n",
853
+ " <th>14247</th>\n",
854
+ " <td>Kentucky</td>\n",
855
+ " <td>21</td>\n",
856
+ " <td>Pike County, KY</td>\n",
857
+ " <td>21195</td>\n",
858
  " <td>2015</td>\n",
859
+ " <td>61831</td>\n",
860
  " </tr>\n",
861
  " </tbody>\n",
862
  "</table>\n",
863
  "</div>"
864
  ],
865
  "text/plain": [
866
+ " State State_Code County County_Code Year Population\n",
867
+ "20737 Missouri 29 Vernon County, MO 29217 2005 20722\n",
868
+ "34648 Texas 48 Knox County, TX 48275 2006 3788\n",
869
+ "8311 Illinois 17 Jasper County, IL 17079 2007 9776\n",
870
+ "31809 Tennessee 47 Clay County, TN 47027 2014 7626\n",
871
+ "14247 Kentucky 21 Pike County, KY 21195 2015 61831"
 
 
 
 
 
 
 
872
  ]
873
  },
874
  "execution_count": 15,
 
913
  " </thead>\n",
914
  " <tbody>\n",
915
  " <tr>\n",
916
+ " <th>237</th>\n",
917
+ " <td>TUOLUMNE</td>\n",
918
+ " <td>CA</td>\n",
919
+ " <td>6109</td>\n",
920
  " </tr>\n",
921
  " <tr>\n",
922
+ " <th>2652</th>\n",
923
+ " <td>KIMBLE</td>\n",
924
+ " <td>TX</td>\n",
925
+ " <td>48267</td>\n",
926
  " </tr>\n",
927
  " <tr>\n",
928
+ " <th>2053</th>\n",
929
+ " <td>COLUMBIANA</td>\n",
930
+ " <td>OH</td>\n",
931
+ " <td>39029</td>\n",
932
  " </tr>\n",
933
  " <tr>\n",
934
+ " <th>2963</th>\n",
935
+ " <td>GRANT</td>\n",
936
+ " <td>WA</td>\n",
937
+ " <td>53025</td>\n",
938
  " </tr>\n",
939
  " <tr>\n",
940
+ " <th>492</th>\n",
941
+ " <td>OGLETHORPE</td>\n",
942
+ " <td>GA</td>\n",
943
+ " <td>13221</td>\n",
944
  " </tr>\n",
945
  " </tbody>\n",
946
  "</table>\n",
 
948
  ],
949
  "text/plain": [
950
  " BUYER_COUNTY BUYER_STATE countyfips\n",
951
+ "237 TUOLUMNE CA 6109\n",
952
+ "2652 KIMBLE TX 48267\n",
953
+ "2053 COLUMBIANA OH 39029\n",
954
+ "2963 GRANT WA 53025\n",
955
+ "492 OGLETHORPE GA 13221"
956
  ]
957
  },
958
  "execution_count": 16,
 
962
  ],
963
  "source": [
964
  "# maps with fips for proper county names\n",
965
+ "fips = pd.read_csv(\"../.01_Data/01_Raw/county_fips.csv\")\n",
966
  "fips.sample(5)"
967
  ]
968
  },
 
1736
  " </thead>\n",
1737
  " <tbody>\n",
1738
  " <tr>\n",
1739
+ " <th>33059</th>\n",
1740
+ " <td>Texas</td>\n",
1741
+ " <td>48</td>\n",
1742
+ " <td>Coryell County, TX</td>\n",
1743
+ " <td>48099</td>\n",
1744
+ " <td>2003</td>\n",
1745
+ " <td>71364</td>\n",
1746
+ " <td>CORYELL</td>\n",
1747
+ " <td>TX</td>\n",
1748
+ " <td>48099</td>\n",
1749
  " <td>both</td>\n",
1750
  " </tr>\n",
1751
  " <tr>\n",
1752
+ " <th>32136</th>\n",
1753
+ " <td>Tennessee</td>\n",
1754
+ " <td>47</td>\n",
1755
+ " <td>Robertson County, TN</td>\n",
1756
+ " <td>47147</td>\n",
1757
+ " <td>2003</td>\n",
1758
+ " <td>57682</td>\n",
1759
+ " <td>ROBERTSON</td>\n",
1760
+ " <td>TN</td>\n",
1761
+ " <td>47147</td>\n",
1762
  " <td>both</td>\n",
1763
  " </tr>\n",
1764
  " <tr>\n",
1765
+ " <th>24181</th>\n",
1766
+ " <td>New York</td>\n",
1767
+ " <td>36</td>\n",
1768
+ " <td>Yates County, NY</td>\n",
1769
+ " <td>36123</td>\n",
1770
+ " <td>2004</td>\n",
1771
+ " <td>25008</td>\n",
1772
+ " <td>YATES</td>\n",
1773
+ " <td>NY</td>\n",
1774
+ " <td>36123</td>\n",
1775
  " <td>both</td>\n",
1776
  " </tr>\n",
1777
  " <tr>\n",
1778
+ " <th>25432</th>\n",
1779
+ " <td>North Carolina</td>\n",
1780
+ " <td>37</td>\n",
1781
+ " <td>Wayne County, NC</td>\n",
1782
+ " <td>37191</td>\n",
1783
  " <td>2007</td>\n",
1784
+ " <td>118942</td>\n",
1785
+ " <td>WAYNE</td>\n",
1786
+ " <td>NC</td>\n",
1787
+ " <td>37191</td>\n",
1788
  " <td>both</td>\n",
1789
  " </tr>\n",
1790
  " <tr>\n",
1791
+ " <th>1498</th>\n",
1792
+ " <td>Arkansas</td>\n",
1793
+ " <td>05</td>\n",
1794
+ " <td>Jackson County, AR</td>\n",
1795
+ " <td>05067</td>\n",
1796
+ " <td>2006</td>\n",
1797
+ " <td>18092</td>\n",
1798
+ " <td>JACKSON</td>\n",
1799
+ " <td>AR</td>\n",
1800
+ " <td>05067</td>\n",
1801
  " <td>both</td>\n",
1802
  " </tr>\n",
1803
  " </tbody>\n",
 
1805
  "</div>"
1806
  ],
1807
  "text/plain": [
1808
+ " State State_Code County County_Code Year \\\n",
1809
+ "33059 Texas 48 Coryell County, TX 48099 2003 \n",
1810
+ "32136 Tennessee 47 Robertson County, TN 47147 2003 \n",
1811
+ "24181 New York 36 Yates County, NY 36123 2004 \n",
1812
+ "25432 North Carolina 37 Wayne County, NC 37191 2007 \n",
1813
+ "1498 Arkansas 05 Jackson County, AR 05067 2006 \n",
1814
  "\n",
1815
+ " Population BUYER_COUNTY BUYER_STATE countyfips _merge \n",
1816
+ "33059 71364 CORYELL TX 48099 both \n",
1817
+ "32136 57682 ROBERTSON TN 47147 both \n",
1818
+ "24181 25008 YATES NY 36123 both \n",
1819
+ "25432 118942 WAYNE NC 37191 both \n",
1820
+ "1498 18092 JACKSON AR 05067 both "
1821
  ]
1822
  },
1823
  "execution_count": 23,
 
1896
  " </thead>\n",
1897
  " <tbody>\n",
1898
  " <tr>\n",
1899
+ " <th>16</th>\n",
1900
+ " <td>Kansas</td>\n",
1901
+ " <td>Kans.</td>\n",
1902
+ " <td>KS</td>\n",
1903
  " </tr>\n",
1904
  " <tr>\n",
1905
+ " <th>5</th>\n",
1906
+ " <td>Colorado</td>\n",
1907
+ " <td>Colo.</td>\n",
1908
+ " <td>CO</td>\n",
1909
  " </tr>\n",
1910
  " <tr>\n",
1911
+ " <th>34</th>\n",
1912
+ " <td>North Dakota</td>\n",
1913
+ " <td>N.D.</td>\n",
1914
+ " <td>ND</td>\n",
1915
  " </tr>\n",
1916
  " <tr>\n",
1917
+ " <th>10</th>\n",
1918
+ " <td>Georgia</td>\n",
1919
+ " <td>Ga.</td>\n",
1920
+ " <td>GA</td>\n",
1921
  " </tr>\n",
1922
  " <tr>\n",
1923
+ " <th>14</th>\n",
1924
+ " <td>Indiana</td>\n",
1925
+ " <td>Ind.</td>\n",
1926
+ " <td>IN</td>\n",
1927
  " </tr>\n",
1928
  " </tbody>\n",
1929
  "</table>\n",
1930
  "</div>"
1931
  ],
1932
  "text/plain": [
1933
+ " state abbrev code\n",
1934
+ "16 Kansas Kans. KS\n",
1935
+ "5 Colorado Colo. CO\n",
1936
+ "34 North Dakota N.D. ND\n",
1937
+ "10 Georgia Ga. GA\n",
1938
+ "14 Indiana Ind. IN"
1939
  ]
1940
  },
1941
  "execution_count": 25,
 
1944
  }
1945
  ],
1946
  "source": [
1947
+ "abbreviations = pd.read_csv(\"../.01_Data/01_Raw/state_abbreviations.csv\")\n",
1948
  "abbreviations.sample(5)"
1949
  ]
1950
  },
 
1999
  " </thead>\n",
2000
  " <tbody>\n",
2001
  " <tr>\n",
2002
+ " <th>16193</th>\n",
2003
+ " <td>Michigan</td>\n",
2004
+ " <td>LAPEER</td>\n",
2005
+ " <td>26087</td>\n",
2006
  " <td>2011</td>\n",
2007
+ " <td>88095</td>\n",
2008
+ " <td>MI</td>\n",
2009
  " </tr>\n",
2010
  " <tr>\n",
2011
+ " <th>24405</th>\n",
2012
+ " <td>North Carolina</td>\n",
2013
+ " <td>CASWELL</td>\n",
2014
+ " <td>37033</td>\n",
2015
+ " <td>2007</td>\n",
2016
+ " <td>23914</td>\n",
2017
+ " <td>NC</td>\n",
2018
  " </tr>\n",
2019
  " <tr>\n",
2020
+ " <th>17883</th>\n",
2021
+ " <td>Mississippi</td>\n",
2022
+ " <td>ATTALA</td>\n",
2023
+ " <td>28007</td>\n",
2024
  " <td>2011</td>\n",
2025
+ " <td>19386</td>\n",
2026
+ " <td>MS</td>\n",
2027
  " </tr>\n",
2028
  " <tr>\n",
2029
+ " <th>30476</th>\n",
2030
+ " <td>South Dakota</td>\n",
2031
+ " <td>CLARK</td>\n",
2032
+ " <td>46025</td>\n",
2033
+ " <td>2007</td>\n",
2034
+ " <td>3711</td>\n",
2035
+ " <td>SD</td>\n",
2036
  " </tr>\n",
2037
  " <tr>\n",
2038
+ " <th>37845</th>\n",
2039
+ " <td>Virginia</td>\n",
2040
+ " <td>NORFOLK CITY</td>\n",
2041
+ " <td>51710</td>\n",
2042
+ " <td>2005</td>\n",
2043
+ " <td>239650</td>\n",
2044
+ " <td>VA</td>\n",
2045
  " </tr>\n",
2046
  " </tbody>\n",
2047
  "</table>\n",
2048
  "</div>"
2049
  ],
2050
  "text/plain": [
2051
+ " State BUYER_COUNTY County_Code Year Population State_Code\n",
2052
+ "16193 Michigan LAPEER 26087 2011 88095 MI\n",
2053
+ "24405 North Carolina CASWELL 37033 2007 23914 NC\n",
2054
+ "17883 Mississippi ATTALA 28007 2011 19386 MS\n",
2055
+ "30476 South Dakota CLARK 46025 2007 3711 SD\n",
2056
+ "37845 Virginia NORFOLK CITY 51710 2005 239650 VA"
2057
  ]
2058
  },
2059
  "execution_count": 27,
 
2110
  " </thead>\n",
2111
  " <tbody>\n",
2112
  " <tr>\n",
2113
+ " <th>16301</th>\n",
2114
+ " <td>Michigan</td>\n",
2115
+ " <td>MI</td>\n",
2116
+ " <td>MARQUETTE</td>\n",
2117
+ " <td>26103</td>\n",
2118
+ " <td>2015</td>\n",
2119
+ " <td>67357</td>\n",
2120
  " </tr>\n",
2121
  " <tr>\n",
2122
+ " <th>31393</th>\n",
2123
  " <td>Tennessee</td>\n",
2124
  " <td>TN</td>\n",
2125
+ " <td>COFFEE</td>\n",
2126
+ " <td>47031</td>\n",
2127
+ " <td>2014</td>\n",
2128
+ " <td>53555</td>\n",
2129
  " </tr>\n",
2130
  " <tr>\n",
2131
+ " <th>21251</th>\n",
2132
+ " <td>Nebraska</td>\n",
2133
+ " <td>NE</td>\n",
2134
+ " <td>BUFFALO</td>\n",
2135
+ " <td>31019</td>\n",
2136
+ " <td>2012</td>\n",
2137
+ " <td>47642</td>\n",
2138
  " </tr>\n",
2139
  " <tr>\n",
2140
+ " <th>16206</th>\n",
2141
+ " <td>Michigan</td>\n",
2142
+ " <td>MI</td>\n",
2143
+ " <td>LEELANAU</td>\n",
2144
+ " <td>26089</td>\n",
2145
+ " <td>2011</td>\n",
2146
+ " <td>21428</td>\n",
2147
  " </tr>\n",
2148
  " <tr>\n",
2149
+ " <th>6815</th>\n",
2150
+ " <td>Idaho</td>\n",
2151
+ " <td>ID</td>\n",
2152
+ " <td>BANNOCK</td>\n",
2153
+ " <td>16005</td>\n",
2154
+ " <td>2006</td>\n",
2155
+ " <td>78491</td>\n",
2156
  " </tr>\n",
2157
  " </tbody>\n",
2158
  "</table>\n",
2159
  "</div>"
2160
  ],
2161
  "text/plain": [
2162
+ " State State_Code County County_Code Year Population\n",
2163
+ "16301 Michigan MI MARQUETTE 26103 2015 67357\n",
2164
+ "31393 Tennessee TN COFFEE 47031 2014 53555\n",
2165
+ "21251 Nebraska NE BUFFALO 31019 2012 47642\n",
2166
+ "16206 Michigan MI LEELANAU 26089 2011 21428\n",
2167
+ "6815 Idaho ID BANNOCK 16005 2006 78491"
2168
  ]
2169
  },
2170
  "execution_count": 28,
 
2223
  "source": [
2224
  "df5.info()"
2225
  ]
 
 
 
 
 
 
 
2226
  }
2227
  ],
2228
  "metadata": {
02_Codes/02_population_script.py CHANGED
@@ -4,9 +4,9 @@ import pandas as pd
4
  pd.set_option("mode.copy_on_write", True)
5
 
6
  # reading the raw files
7
- df = pd.read_csv("01_Data/01_Raw/raw_population.txt", sep="\t")
8
- fips = pd.read_csv("01_Data/01_Raw/county_fips.csv")
9
- abbreviations = pd.read_csv("01_Data/01_Raw/state_abbreviations.csv")
10
 
11
  # ------------------------------------------
12
  # dropping the unnecessary columns
@@ -133,4 +133,4 @@ df5 = df5[
133
  # ------------------------------------------
134
 
135
  # Writing to Parquet
136
- df5.to_parquet("01_Data/02_processed/01_Population.parquet", index=False)
 
4
  pd.set_option("mode.copy_on_write", True)
5
 
6
  # reading the raw files
7
+ df = pd.read_csv(".01_Data/01_Raw/raw_population.txt", sep="\t")
8
+ fips = pd.read_csv(".01_Data/01_Raw/county_fips.csv")
9
+ abbreviations = pd.read_csv(".01_Data/01_Raw/state_abbreviations.csv")
10
 
11
  # ------------------------------------------
12
  # dropping the unnecessary columns
 
133
  # ------------------------------------------
134
 
135
  # Writing to Parquet
136
+ df5.to_parquet(".01_Data/02_processed/01_Population.parquet", index=False)
02_Codes/03_mortality_eda.ipynb ADDED
@@ -0,0 +1,1640 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# Impoting required packages\n",
10
+ "import pandas as pd\n",
11
+ "import numpy as np\n",
12
+ "import zipfile\n",
13
+ "\n",
14
+ "# setting default option\n",
15
+ "pd.set_option(\"mode.copy_on_write\", True)"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": 2,
21
+ "metadata": {},
22
+ "outputs": [
23
+ {
24
+ "data": {
25
+ "text/plain": [
26
+ "['Underlying Cause of Death, 2009.txt',\n",
27
+ " '__MACOSX/',\n",
28
+ " '__MACOSX/._Underlying Cause of Death, 2009.txt',\n",
29
+ " 'Underlying Cause of Death, 2008.txt',\n",
30
+ " 'Underlying Cause of Death, 2003.txt',\n",
31
+ " 'Underlying Cause of Death, 2014.txt',\n",
32
+ " 'Underlying Cause of Death, 2015.txt',\n",
33
+ " 'Underlying Cause of Death, 2005.txt',\n",
34
+ " 'Underlying Cause of Death, 2011.txt',\n",
35
+ " 'Underlying Cause of Death, 2010.txt',\n",
36
+ " 'Underlying Cause of Death, 2004.txt',\n",
37
+ " 'Underlying Cause of Death, 2012.txt',\n",
38
+ " 'Underlying Cause of Death, 2006.txt',\n",
39
+ " 'Underlying Cause of Death, 2007.txt',\n",
40
+ " 'Underlying Cause of Death, 2013.txt']"
41
+ ]
42
+ },
43
+ "execution_count": 2,
44
+ "metadata": {},
45
+ "output_type": "execute_result"
46
+ }
47
+ ],
48
+ "source": [
49
+ "# View the files present in the Zip file\n",
50
+ "z = zipfile.ZipFile(\"../.01_Data/01_Raw/raw_mortality.zip\")\n",
51
+ "z.namelist()"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 3,
57
+ "metadata": {},
58
+ "outputs": [
59
+ {
60
+ "data": {
61
+ "text/plain": [
62
+ "['Underlying Cause of Death, 2003.txt',\n",
63
+ " 'Underlying Cause of Death, 2004.txt',\n",
64
+ " 'Underlying Cause of Death, 2005.txt',\n",
65
+ " 'Underlying Cause of Death, 2006.txt',\n",
66
+ " 'Underlying Cause of Death, 2007.txt',\n",
67
+ " 'Underlying Cause of Death, 2008.txt',\n",
68
+ " 'Underlying Cause of Death, 2009.txt',\n",
69
+ " 'Underlying Cause of Death, 2010.txt',\n",
70
+ " 'Underlying Cause of Death, 2011.txt',\n",
71
+ " 'Underlying Cause of Death, 2012.txt',\n",
72
+ " 'Underlying Cause of Death, 2013.txt',\n",
73
+ " 'Underlying Cause of Death, 2014.txt',\n",
74
+ " 'Underlying Cause of Death, 2015.txt']"
75
+ ]
76
+ },
77
+ "execution_count": 3,
78
+ "metadata": {},
79
+ "output_type": "execute_result"
80
+ }
81
+ ],
82
+ "source": [
83
+ "# creating list of files which start with \"Underlying\" so as to ignore system files\n",
84
+ "file_list = sorted([f for f in z.namelist() if f.startswith(\"Underlying\")])\n",
85
+ "file_list"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 4,
91
+ "metadata": {},
92
+ "outputs": [
93
+ {
94
+ "data": {
95
+ "text/html": [
96
+ "<div>\n",
97
+ "<style scoped>\n",
98
+ " .dataframe tbody tr th:only-of-type {\n",
99
+ " vertical-align: middle;\n",
100
+ " }\n",
101
+ "\n",
102
+ " .dataframe tbody tr th {\n",
103
+ " vertical-align: top;\n",
104
+ " }\n",
105
+ "\n",
106
+ " .dataframe thead th {\n",
107
+ " text-align: right;\n",
108
+ " }\n",
109
+ "</style>\n",
110
+ "<table border=\"1\" class=\"dataframe\">\n",
111
+ " <thead>\n",
112
+ " <tr style=\"text-align: right;\">\n",
113
+ " <th></th>\n",
114
+ " <th>Notes</th>\n",
115
+ " <th>County</th>\n",
116
+ " <th>County Code</th>\n",
117
+ " <th>Year</th>\n",
118
+ " <th>Year Code</th>\n",
119
+ " <th>Drug/Alcohol Induced Cause</th>\n",
120
+ " <th>Drug/Alcohol Induced Cause Code</th>\n",
121
+ " <th>Deaths</th>\n",
122
+ " </tr>\n",
123
+ " </thead>\n",
124
+ " <tbody>\n",
125
+ " <tr>\n",
126
+ " <th>3308</th>\n",
127
+ " <td>NaN</td>\n",
128
+ " <td>Union County, TN</td>\n",
129
+ " <td>47173.0</td>\n",
130
+ " <td>2003.0</td>\n",
131
+ " <td>2003.0</td>\n",
132
+ " <td>All other non-drug and non-alcohol causes</td>\n",
133
+ " <td>O9</td>\n",
134
+ " <td>165.0</td>\n",
135
+ " </tr>\n",
136
+ " <tr>\n",
137
+ " <th>2597</th>\n",
138
+ " <td>NaN</td>\n",
139
+ " <td>Rutherford County, NC</td>\n",
140
+ " <td>37161.0</td>\n",
141
+ " <td>2003.0</td>\n",
142
+ " <td>2003.0</td>\n",
143
+ " <td>All other non-drug and non-alcohol causes</td>\n",
144
+ " <td>O9</td>\n",
145
+ " <td>731.0</td>\n",
146
+ " </tr>\n",
147
+ " <tr>\n",
148
+ " <th>717</th>\n",
149
+ " <td>NaN</td>\n",
150
+ " <td>Glascock County, GA</td>\n",
151
+ " <td>13125.0</td>\n",
152
+ " <td>2003.0</td>\n",
153
+ " <td>2003.0</td>\n",
154
+ " <td>All other non-drug and non-alcohol causes</td>\n",
155
+ " <td>O9</td>\n",
156
+ " <td>40.0</td>\n",
157
+ " </tr>\n",
158
+ " <tr>\n",
159
+ " <th>2261</th>\n",
160
+ " <td>NaN</td>\n",
161
+ " <td>Hillsborough County, NH</td>\n",
162
+ " <td>33011.0</td>\n",
163
+ " <td>2003.0</td>\n",
164
+ " <td>2003.0</td>\n",
165
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
166
+ " <td>D1</td>\n",
167
+ " <td>23.0</td>\n",
168
+ " </tr>\n",
169
+ " <tr>\n",
170
+ " <th>3181</th>\n",
171
+ " <td>NaN</td>\n",
172
+ " <td>McPherson County, SD</td>\n",
173
+ " <td>46089.0</td>\n",
174
+ " <td>2003.0</td>\n",
175
+ " <td>2003.0</td>\n",
176
+ " <td>All other non-drug and non-alcohol causes</td>\n",
177
+ " <td>O9</td>\n",
178
+ " <td>39.0</td>\n",
179
+ " </tr>\n",
180
+ " </tbody>\n",
181
+ "</table>\n",
182
+ "</div>"
183
+ ],
184
+ "text/plain": [
185
+ " Notes County County Code Year Year Code \\\n",
186
+ "3308 NaN Union County, TN 47173.0 2003.0 2003.0 \n",
187
+ "2597 NaN Rutherford County, NC 37161.0 2003.0 2003.0 \n",
188
+ "717 NaN Glascock County, GA 13125.0 2003.0 2003.0 \n",
189
+ "2261 NaN Hillsborough County, NH 33011.0 2003.0 2003.0 \n",
190
+ "3181 NaN McPherson County, SD 46089.0 2003.0 2003.0 \n",
191
+ "\n",
192
+ " Drug/Alcohol Induced Cause \\\n",
193
+ "3308 All other non-drug and non-alcohol causes \n",
194
+ "2597 All other non-drug and non-alcohol causes \n",
195
+ "717 All other non-drug and non-alcohol causes \n",
196
+ "2261 Drug poisonings (overdose) Unintentional (X40-... \n",
197
+ "3181 All other non-drug and non-alcohol causes \n",
198
+ "\n",
199
+ " Drug/Alcohol Induced Cause Code Deaths \n",
200
+ "3308 O9 165.0 \n",
201
+ "2597 O9 731.0 \n",
202
+ "717 O9 40.0 \n",
203
+ "2261 D1 23.0 \n",
204
+ "3181 O9 39.0 "
205
+ ]
206
+ },
207
+ "execution_count": 4,
208
+ "metadata": {},
209
+ "output_type": "execute_result"
210
+ }
211
+ ],
212
+ "source": [
213
+ "# read a single file to understand structure and cleaning rules required\n",
214
+ "test = pd.read_csv(z.open(file_list[0]), sep=\"\\t\")\n",
215
+ "test.sample(5)"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "execution_count": 5,
221
+ "metadata": {},
222
+ "outputs": [
223
+ {
224
+ "name": "stdout",
225
+ "output_type": "stream",
226
+ "text": [
227
+ "<class 'pandas.core.frame.DataFrame'>\n",
228
+ "RangeIndex: 4102 entries, 0 to 4101\n",
229
+ "Data columns (total 8 columns):\n",
230
+ " # Column Non-Null Count Dtype \n",
231
+ "--- ------ -------------- ----- \n",
232
+ " 0 Notes 15 non-null object \n",
233
+ " 1 County 4087 non-null object \n",
234
+ " 2 County Code 4087 non-null float64\n",
235
+ " 3 Year 4087 non-null float64\n",
236
+ " 4 Year Code 4087 non-null float64\n",
237
+ " 5 Drug/Alcohol Induced Cause 4087 non-null object \n",
238
+ " 6 Drug/Alcohol Induced Cause Code 4087 non-null object \n",
239
+ " 7 Deaths 4087 non-null float64\n",
240
+ "dtypes: float64(4), object(4)\n",
241
+ "memory usage: 256.5+ KB\n"
242
+ ]
243
+ }
244
+ ],
245
+ "source": [
246
+ "test.info()"
247
+ ]
248
+ },
249
+ {
250
+ "cell_type": "code",
251
+ "execution_count": 6,
252
+ "metadata": {},
253
+ "outputs": [
254
+ {
255
+ "data": {
256
+ "text/html": [
257
+ "<div>\n",
258
+ "<style scoped>\n",
259
+ " .dataframe tbody tr th:only-of-type {\n",
260
+ " vertical-align: middle;\n",
261
+ " }\n",
262
+ "\n",
263
+ " .dataframe tbody tr th {\n",
264
+ " vertical-align: top;\n",
265
+ " }\n",
266
+ "\n",
267
+ " .dataframe thead th {\n",
268
+ " text-align: right;\n",
269
+ " }\n",
270
+ "</style>\n",
271
+ "<table border=\"1\" class=\"dataframe\">\n",
272
+ " <thead>\n",
273
+ " <tr style=\"text-align: right;\">\n",
274
+ " <th></th>\n",
275
+ " <th>Notes</th>\n",
276
+ " <th>County</th>\n",
277
+ " <th>County Code</th>\n",
278
+ " <th>Year</th>\n",
279
+ " <th>Year Code</th>\n",
280
+ " <th>Drug/Alcohol Induced Cause</th>\n",
281
+ " <th>Drug/Alcohol Induced Cause Code</th>\n",
282
+ " <th>Deaths</th>\n",
283
+ " </tr>\n",
284
+ " </thead>\n",
285
+ " <tbody>\n",
286
+ " <tr>\n",
287
+ " <th>4087</th>\n",
288
+ " <td>---</td>\n",
289
+ " <td>NaN</td>\n",
290
+ " <td>NaN</td>\n",
291
+ " <td>NaN</td>\n",
292
+ " <td>NaN</td>\n",
293
+ " <td>NaN</td>\n",
294
+ " <td>NaN</td>\n",
295
+ " <td>NaN</td>\n",
296
+ " </tr>\n",
297
+ " <tr>\n",
298
+ " <th>4088</th>\n",
299
+ " <td>Dataset: Underlying Cause of Death, 1999-2017</td>\n",
300
+ " <td>NaN</td>\n",
301
+ " <td>NaN</td>\n",
302
+ " <td>NaN</td>\n",
303
+ " <td>NaN</td>\n",
304
+ " <td>NaN</td>\n",
305
+ " <td>NaN</td>\n",
306
+ " <td>NaN</td>\n",
307
+ " </tr>\n",
308
+ " <tr>\n",
309
+ " <th>4089</th>\n",
310
+ " <td>Query Parameters:</td>\n",
311
+ " <td>NaN</td>\n",
312
+ " <td>NaN</td>\n",
313
+ " <td>NaN</td>\n",
314
+ " <td>NaN</td>\n",
315
+ " <td>NaN</td>\n",
316
+ " <td>NaN</td>\n",
317
+ " <td>NaN</td>\n",
318
+ " </tr>\n",
319
+ " <tr>\n",
320
+ " <th>4090</th>\n",
321
+ " <td>Group By: County; Year; Drug/Alcohol Induced C...</td>\n",
322
+ " <td>NaN</td>\n",
323
+ " <td>NaN</td>\n",
324
+ " <td>NaN</td>\n",
325
+ " <td>NaN</td>\n",
326
+ " <td>NaN</td>\n",
327
+ " <td>NaN</td>\n",
328
+ " <td>NaN</td>\n",
329
+ " </tr>\n",
330
+ " <tr>\n",
331
+ " <th>4091</th>\n",
332
+ " <td>Show Totals: Disabled</td>\n",
333
+ " <td>NaN</td>\n",
334
+ " <td>NaN</td>\n",
335
+ " <td>NaN</td>\n",
336
+ " <td>NaN</td>\n",
337
+ " <td>NaN</td>\n",
338
+ " <td>NaN</td>\n",
339
+ " <td>NaN</td>\n",
340
+ " </tr>\n",
341
+ " <tr>\n",
342
+ " <th>4092</th>\n",
343
+ " <td>Show Zero Values: Disabled</td>\n",
344
+ " <td>NaN</td>\n",
345
+ " <td>NaN</td>\n",
346
+ " <td>NaN</td>\n",
347
+ " <td>NaN</td>\n",
348
+ " <td>NaN</td>\n",
349
+ " <td>NaN</td>\n",
350
+ " <td>NaN</td>\n",
351
+ " </tr>\n",
352
+ " <tr>\n",
353
+ " <th>4093</th>\n",
354
+ " <td>Show Suppressed: False</td>\n",
355
+ " <td>NaN</td>\n",
356
+ " <td>NaN</td>\n",
357
+ " <td>NaN</td>\n",
358
+ " <td>NaN</td>\n",
359
+ " <td>NaN</td>\n",
360
+ " <td>NaN</td>\n",
361
+ " <td>NaN</td>\n",
362
+ " </tr>\n",
363
+ " <tr>\n",
364
+ " <th>4094</th>\n",
365
+ " <td>---</td>\n",
366
+ " <td>NaN</td>\n",
367
+ " <td>NaN</td>\n",
368
+ " <td>NaN</td>\n",
369
+ " <td>NaN</td>\n",
370
+ " <td>NaN</td>\n",
371
+ " <td>NaN</td>\n",
372
+ " <td>NaN</td>\n",
373
+ " </tr>\n",
374
+ " <tr>\n",
375
+ " <th>4095</th>\n",
376
+ " <td>Help: See http://wonder.cdc.gov/wonder/help/uc...</td>\n",
377
+ " <td>NaN</td>\n",
378
+ " <td>NaN</td>\n",
379
+ " <td>NaN</td>\n",
380
+ " <td>NaN</td>\n",
381
+ " <td>NaN</td>\n",
382
+ " <td>NaN</td>\n",
383
+ " <td>NaN</td>\n",
384
+ " </tr>\n",
385
+ " <tr>\n",
386
+ " <th>4096</th>\n",
387
+ " <td>---</td>\n",
388
+ " <td>NaN</td>\n",
389
+ " <td>NaN</td>\n",
390
+ " <td>NaN</td>\n",
391
+ " <td>NaN</td>\n",
392
+ " <td>NaN</td>\n",
393
+ " <td>NaN</td>\n",
394
+ " <td>NaN</td>\n",
395
+ " </tr>\n",
396
+ " <tr>\n",
397
+ " <th>4097</th>\n",
398
+ " <td>Suggested Citation: Centers for Disease Contro...</td>\n",
399
+ " <td>NaN</td>\n",
400
+ " <td>NaN</td>\n",
401
+ " <td>NaN</td>\n",
402
+ " <td>NaN</td>\n",
403
+ " <td>NaN</td>\n",
404
+ " <td>NaN</td>\n",
405
+ " <td>NaN</td>\n",
406
+ " </tr>\n",
407
+ " <tr>\n",
408
+ " <th>4098</th>\n",
409
+ " <td>1999-2017 on CDC WONDER Online Database, relea...</td>\n",
410
+ " <td>NaN</td>\n",
411
+ " <td>NaN</td>\n",
412
+ " <td>NaN</td>\n",
413
+ " <td>NaN</td>\n",
414
+ " <td>NaN</td>\n",
415
+ " <td>NaN</td>\n",
416
+ " <td>NaN</td>\n",
417
+ " </tr>\n",
418
+ " <tr>\n",
419
+ " <th>4099</th>\n",
420
+ " <td>compiled from data provided by the 57 vital st...</td>\n",
421
+ " <td>NaN</td>\n",
422
+ " <td>NaN</td>\n",
423
+ " <td>NaN</td>\n",
424
+ " <td>NaN</td>\n",
425
+ " <td>NaN</td>\n",
426
+ " <td>NaN</td>\n",
427
+ " <td>NaN</td>\n",
428
+ " </tr>\n",
429
+ " <tr>\n",
430
+ " <th>4100</th>\n",
431
+ " <td>at http://wonder.cdc.gov/ucd-icd10.html on Oct...</td>\n",
432
+ " <td>NaN</td>\n",
433
+ " <td>NaN</td>\n",
434
+ " <td>NaN</td>\n",
435
+ " <td>NaN</td>\n",
436
+ " <td>NaN</td>\n",
437
+ " <td>NaN</td>\n",
438
+ " <td>NaN</td>\n",
439
+ " </tr>\n",
440
+ " <tr>\n",
441
+ " <th>4101</th>\n",
442
+ " <td>---</td>\n",
443
+ " <td>NaN</td>\n",
444
+ " <td>NaN</td>\n",
445
+ " <td>NaN</td>\n",
446
+ " <td>NaN</td>\n",
447
+ " <td>NaN</td>\n",
448
+ " <td>NaN</td>\n",
449
+ " <td>NaN</td>\n",
450
+ " </tr>\n",
451
+ " </tbody>\n",
452
+ "</table>\n",
453
+ "</div>"
454
+ ],
455
+ "text/plain": [
456
+ " Notes County County Code \\\n",
457
+ "4087 --- NaN NaN \n",
458
+ "4088 Dataset: Underlying Cause of Death, 1999-2017 NaN NaN \n",
459
+ "4089 Query Parameters: NaN NaN \n",
460
+ "4090 Group By: County; Year; Drug/Alcohol Induced C... NaN NaN \n",
461
+ "4091 Show Totals: Disabled NaN NaN \n",
462
+ "4092 Show Zero Values: Disabled NaN NaN \n",
463
+ "4093 Show Suppressed: False NaN NaN \n",
464
+ "4094 --- NaN NaN \n",
465
+ "4095 Help: See http://wonder.cdc.gov/wonder/help/uc... NaN NaN \n",
466
+ "4096 --- NaN NaN \n",
467
+ "4097 Suggested Citation: Centers for Disease Contro... NaN NaN \n",
468
+ "4098 1999-2017 on CDC WONDER Online Database, relea... NaN NaN \n",
469
+ "4099 compiled from data provided by the 57 vital st... NaN NaN \n",
470
+ "4100 at http://wonder.cdc.gov/ucd-icd10.html on Oct... NaN NaN \n",
471
+ "4101 --- NaN NaN \n",
472
+ "\n",
473
+ " Year Year Code Drug/Alcohol Induced Cause \\\n",
474
+ "4087 NaN NaN NaN \n",
475
+ "4088 NaN NaN NaN \n",
476
+ "4089 NaN NaN NaN \n",
477
+ "4090 NaN NaN NaN \n",
478
+ "4091 NaN NaN NaN \n",
479
+ "4092 NaN NaN NaN \n",
480
+ "4093 NaN NaN NaN \n",
481
+ "4094 NaN NaN NaN \n",
482
+ "4095 NaN NaN NaN \n",
483
+ "4096 NaN NaN NaN \n",
484
+ "4097 NaN NaN NaN \n",
485
+ "4098 NaN NaN NaN \n",
486
+ "4099 NaN NaN NaN \n",
487
+ "4100 NaN NaN NaN \n",
488
+ "4101 NaN NaN NaN \n",
489
+ "\n",
490
+ " Drug/Alcohol Induced Cause Code Deaths \n",
491
+ "4087 NaN NaN \n",
492
+ "4088 NaN NaN \n",
493
+ "4089 NaN NaN \n",
494
+ "4090 NaN NaN \n",
495
+ "4091 NaN NaN \n",
496
+ "4092 NaN NaN \n",
497
+ "4093 NaN NaN \n",
498
+ "4094 NaN NaN \n",
499
+ "4095 NaN NaN \n",
500
+ "4096 NaN NaN \n",
501
+ "4097 NaN NaN \n",
502
+ "4098 NaN NaN \n",
503
+ "4099 NaN NaN \n",
504
+ "4100 NaN NaN \n",
505
+ "4101 NaN NaN "
506
+ ]
507
+ },
508
+ "execution_count": 6,
509
+ "metadata": {},
510
+ "output_type": "execute_result"
511
+ }
512
+ ],
513
+ "source": [
514
+ "# viewing the rows which have non-null values in Notes column\n",
515
+ "test[test[\"Notes\"].notnull()]"
516
+ ]
517
+ },
518
+ {
519
+ "cell_type": "markdown",
520
+ "metadata": {},
521
+ "source": [
522
+ "We can clean notes in a similar was as we did for the other dataset"
523
+ ]
524
+ },
525
+ {
526
+ "cell_type": "code",
527
+ "execution_count": 7,
528
+ "metadata": {},
529
+ "outputs": [],
530
+ "source": [
531
+ "# read data from all the files and append to list\n",
532
+ "df_list = []\n",
533
+ "for file in file_list:\n",
534
+ " # read individual files\n",
535
+ " df_temp = pd.read_csv(z.open(file), sep=\"\\t\")\n",
536
+ "\n",
537
+ " # drop the notes columns and remove rows with null values in State column\n",
538
+ " df_temp.drop(columns=[\"Notes\"], inplace=True)\n",
539
+ " df_temp.dropna(subset=[\"County\"], inplace=True)\n",
540
+ "\n",
541
+ " # add the cleaned temp Df to the main list\n",
542
+ " df_list.append(df_temp)"
543
+ ]
544
+ },
545
+ {
546
+ "cell_type": "code",
547
+ "execution_count": 8,
548
+ "metadata": {},
549
+ "outputs": [
550
+ {
551
+ "data": {
552
+ "text/html": [
553
+ "<div>\n",
554
+ "<style scoped>\n",
555
+ " .dataframe tbody tr th:only-of-type {\n",
556
+ " vertical-align: middle;\n",
557
+ " }\n",
558
+ "\n",
559
+ " .dataframe tbody tr th {\n",
560
+ " vertical-align: top;\n",
561
+ " }\n",
562
+ "\n",
563
+ " .dataframe thead th {\n",
564
+ " text-align: right;\n",
565
+ " }\n",
566
+ "</style>\n",
567
+ "<table border=\"1\" class=\"dataframe\">\n",
568
+ " <thead>\n",
569
+ " <tr style=\"text-align: right;\">\n",
570
+ " <th></th>\n",
571
+ " <th>County</th>\n",
572
+ " <th>County Code</th>\n",
573
+ " <th>Year</th>\n",
574
+ " <th>Year Code</th>\n",
575
+ " <th>Drug/Alcohol Induced Cause</th>\n",
576
+ " <th>Drug/Alcohol Induced Cause Code</th>\n",
577
+ " <th>Deaths</th>\n",
578
+ " </tr>\n",
579
+ " </thead>\n",
580
+ " <tbody>\n",
581
+ " <tr>\n",
582
+ " <th>32856</th>\n",
583
+ " <td>Sequoyah County, OK</td>\n",
584
+ " <td>40135.0</td>\n",
585
+ " <td>2010.0</td>\n",
586
+ " <td>2010.0</td>\n",
587
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
588
+ " <td>D1</td>\n",
589
+ " <td>11.0</td>\n",
590
+ " </tr>\n",
591
+ " <tr>\n",
592
+ " <th>11096</th>\n",
593
+ " <td>Stark County, OH</td>\n",
594
+ " <td>39151.0</td>\n",
595
+ " <td>2005.0</td>\n",
596
+ " <td>2005.0</td>\n",
597
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
598
+ " <td>D1</td>\n",
599
+ " <td>16.0</td>\n",
600
+ " </tr>\n",
601
+ " <tr>\n",
602
+ " <th>48071</th>\n",
603
+ " <td>Butte County, CA</td>\n",
604
+ " <td>6007.0</td>\n",
605
+ " <td>2014.0</td>\n",
606
+ " <td>2014.0</td>\n",
607
+ " <td>All other alcohol-induced causes</td>\n",
608
+ " <td>A9</td>\n",
609
+ " <td>42.0</td>\n",
610
+ " </tr>\n",
611
+ " <tr>\n",
612
+ " <th>2822</th>\n",
613
+ " <td>Garfield County, OK</td>\n",
614
+ " <td>40047.0</td>\n",
615
+ " <td>2003.0</td>\n",
616
+ " <td>2003.0</td>\n",
617
+ " <td>All other non-drug and non-alcohol causes</td>\n",
618
+ " <td>O9</td>\n",
619
+ " <td>676.0</td>\n",
620
+ " </tr>\n",
621
+ " <tr>\n",
622
+ " <th>35841</th>\n",
623
+ " <td>Terrebonne Parish, LA</td>\n",
624
+ " <td>22109.0</td>\n",
625
+ " <td>2011.0</td>\n",
626
+ " <td>2011.0</td>\n",
627
+ " <td>All other non-drug and non-alcohol causes</td>\n",
628
+ " <td>O9</td>\n",
629
+ " <td>952.0</td>\n",
630
+ " </tr>\n",
631
+ " </tbody>\n",
632
+ "</table>\n",
633
+ "</div>"
634
+ ],
635
+ "text/plain": [
636
+ " County County Code Year Year Code \\\n",
637
+ "32856 Sequoyah County, OK 40135.0 2010.0 2010.0 \n",
638
+ "11096 Stark County, OH 39151.0 2005.0 2005.0 \n",
639
+ "48071 Butte County, CA 6007.0 2014.0 2014.0 \n",
640
+ "2822 Garfield County, OK 40047.0 2003.0 2003.0 \n",
641
+ "35841 Terrebonne Parish, LA 22109.0 2011.0 2011.0 \n",
642
+ "\n",
643
+ " Drug/Alcohol Induced Cause \\\n",
644
+ "32856 Drug poisonings (overdose) Unintentional (X40-... \n",
645
+ "11096 Drug poisonings (overdose) Unintentional (X40-... \n",
646
+ "48071 All other alcohol-induced causes \n",
647
+ "2822 All other non-drug and non-alcohol causes \n",
648
+ "35841 All other non-drug and non-alcohol causes \n",
649
+ "\n",
650
+ " Drug/Alcohol Induced Cause Code Deaths \n",
651
+ "32856 D1 11.0 \n",
652
+ "11096 D1 16.0 \n",
653
+ "48071 A9 42.0 \n",
654
+ "2822 O9 676.0 \n",
655
+ "35841 O9 952.0 "
656
+ ]
657
+ },
658
+ "execution_count": 8,
659
+ "metadata": {},
660
+ "output_type": "execute_result"
661
+ }
662
+ ],
663
+ "source": [
664
+ "# create the dataframe\n",
665
+ "df = pd.concat(df_list, ignore_index=True)\n",
666
+ "df.sample(5)"
667
+ ]
668
+ },
669
+ {
670
+ "cell_type": "code",
671
+ "execution_count": 9,
672
+ "metadata": {},
673
+ "outputs": [
674
+ {
675
+ "data": {
676
+ "text/plain": [
677
+ "County 0\n",
678
+ "County Code 0\n",
679
+ "Year 0\n",
680
+ "Year Code 0\n",
681
+ "Drug/Alcohol Induced Cause 0\n",
682
+ "Drug/Alcohol Induced Cause Code 0\n",
683
+ "Deaths 0\n",
684
+ "dtype: int64"
685
+ ]
686
+ },
687
+ "execution_count": 9,
688
+ "metadata": {},
689
+ "output_type": "execute_result"
690
+ }
691
+ ],
692
+ "source": [
693
+ "# check for null values\n",
694
+ "df.isnull().sum()"
695
+ ]
696
+ },
697
+ {
698
+ "cell_type": "code",
699
+ "execution_count": 10,
700
+ "metadata": {},
701
+ "outputs": [
702
+ {
703
+ "name": "stdout",
704
+ "output_type": "stream",
705
+ "text": [
706
+ "<class 'pandas.core.frame.DataFrame'>\n",
707
+ "RangeIndex: 57241 entries, 0 to 57240\n",
708
+ "Data columns (total 7 columns):\n",
709
+ " # Column Non-Null Count Dtype \n",
710
+ "--- ------ -------------- ----- \n",
711
+ " 0 County 57241 non-null object \n",
712
+ " 1 County Code 57241 non-null float64\n",
713
+ " 2 Year 57241 non-null float64\n",
714
+ " 3 Year Code 57241 non-null float64\n",
715
+ " 4 Drug/Alcohol Induced Cause 57241 non-null object \n",
716
+ " 5 Drug/Alcohol Induced Cause Code 57241 non-null object \n",
717
+ " 6 Deaths 57241 non-null object \n",
718
+ "dtypes: float64(3), object(4)\n",
719
+ "memory usage: 3.1+ MB\n"
720
+ ]
721
+ }
722
+ ],
723
+ "source": [
724
+ "df.info()"
725
+ ]
726
+ },
727
+ {
728
+ "cell_type": "code",
729
+ "execution_count": 11,
730
+ "metadata": {},
731
+ "outputs": [],
732
+ "source": [
733
+ "# Cleaning the data\n",
734
+ "df2 = df.copy()\n",
735
+ "\n",
736
+ "# Pad county code with 0 for consistency with other data sets\n",
737
+ "df2[\"County Code\"] = df2[\"County Code\"].astype(int).astype(str).str.zfill(5)\n",
738
+ "\n",
739
+ "# Convert Year to Int\n",
740
+ "df2[\"Year\"] = df2[\"Year\"].astype(int)\n",
741
+ "\n",
742
+ "# Convert Deaths to Int\n",
743
+ "df2[\"Deaths\"] = df2[\"Deaths\"].replace(\"Missing\", np.nan)\n",
744
+ "df2[\"Deaths\"] = (\n",
745
+ " df2[\"Deaths\"].astype(float).astype(\"Int64\")\n",
746
+ ") # making it as int64 so that we retain null values"
747
+ ]
748
+ },
749
+ {
750
+ "cell_type": "code",
751
+ "execution_count": 12,
752
+ "metadata": {},
753
+ "outputs": [
754
+ {
755
+ "data": {
756
+ "text/plain": [
757
+ "array(['All other non-drug and non-alcohol causes',\n",
758
+ " 'Drug poisonings (overdose) Unintentional (X40-X44)',\n",
759
+ " 'All other alcohol-induced causes',\n",
760
+ " 'All other drug-induced causes',\n",
761
+ " 'Drug poisonings (overdose) Suicide (X60-X64)',\n",
762
+ " 'Drug poisonings (overdose) Undetermined (Y10-Y14)',\n",
763
+ " 'Alcohol poisonings (overdose) (X45, X65, Y15)',\n",
764
+ " 'Drug poisonings (overdose) Homicide (X85)'], dtype=object)"
765
+ ]
766
+ },
767
+ "execution_count": 12,
768
+ "metadata": {},
769
+ "output_type": "execute_result"
770
+ }
771
+ ],
772
+ "source": [
773
+ "# Check the causes of death present\n",
774
+ "df2[\"Drug/Alcohol Induced Cause\"].unique()"
775
+ ]
776
+ },
777
+ {
778
+ "cell_type": "code",
779
+ "execution_count": 13,
780
+ "metadata": {},
781
+ "outputs": [],
782
+ "source": [
783
+ "# Filter the data to only include drug related deaths\n",
784
+ "required_causes = [\n",
785
+ " \"Drug poisonings (overdose) Unintentional (X40-X44)\",\n",
786
+ " \"All other drug-induced causes\",\n",
787
+ " \"Drug poisonings (overdose) Homicide (X85)\",\n",
788
+ " \"Drug poisonings (overdose) Suicide (X60-X64)\",\n",
789
+ " \"Drug poisonings (overdose) Undetermined (Y10-Y14)\",\n",
790
+ "]"
791
+ ]
792
+ },
793
+ {
794
+ "cell_type": "code",
795
+ "execution_count": 14,
796
+ "metadata": {},
797
+ "outputs": [],
798
+ "source": [
799
+ "df3 = df2[df2[\"Drug/Alcohol Induced Cause\"].isin(required_causes)]"
800
+ ]
801
+ },
802
+ {
803
+ "cell_type": "code",
804
+ "execution_count": 15,
805
+ "metadata": {},
806
+ "outputs": [],
807
+ "source": [
808
+ "# remove extra columns\n",
809
+ "df3.drop(columns=[\"Year Code\", \"Drug/Alcohol Induced Cause Code\"], inplace=True)"
810
+ ]
811
+ },
812
+ {
813
+ "cell_type": "code",
814
+ "execution_count": 16,
815
+ "metadata": {},
816
+ "outputs": [
817
+ {
818
+ "data": {
819
+ "text/html": [
820
+ "<div>\n",
821
+ "<style scoped>\n",
822
+ " .dataframe tbody tr th:only-of-type {\n",
823
+ " vertical-align: middle;\n",
824
+ " }\n",
825
+ "\n",
826
+ " .dataframe tbody tr th {\n",
827
+ " vertical-align: top;\n",
828
+ " }\n",
829
+ "\n",
830
+ " .dataframe thead th {\n",
831
+ " text-align: right;\n",
832
+ " }\n",
833
+ "</style>\n",
834
+ "<table border=\"1\" class=\"dataframe\">\n",
835
+ " <thead>\n",
836
+ " <tr style=\"text-align: right;\">\n",
837
+ " <th></th>\n",
838
+ " <th>County</th>\n",
839
+ " <th>County Code</th>\n",
840
+ " <th>Year</th>\n",
841
+ " <th>Drug/Alcohol Induced Cause</th>\n",
842
+ " <th>Deaths</th>\n",
843
+ " </tr>\n",
844
+ " </thead>\n",
845
+ " <tbody>\n",
846
+ " <tr>\n",
847
+ " <th>30939</th>\n",
848
+ " <td>Wabash County, IN</td>\n",
849
+ " <td>18169</td>\n",
850
+ " <td>2010</td>\n",
851
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
852
+ " <td>10</td>\n",
853
+ " </tr>\n",
854
+ " <tr>\n",
855
+ " <th>36770</th>\n",
856
+ " <td>Cayuga County, NY</td>\n",
857
+ " <td>36011</td>\n",
858
+ " <td>2011</td>\n",
859
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
860
+ " <td>10</td>\n",
861
+ " </tr>\n",
862
+ " <tr>\n",
863
+ " <th>2317</th>\n",
864
+ " <td>Passaic County, NJ</td>\n",
865
+ " <td>34031</td>\n",
866
+ " <td>2003</td>\n",
867
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
868
+ " <td>28</td>\n",
869
+ " </tr>\n",
870
+ " <tr>\n",
871
+ " <th>9869</th>\n",
872
+ " <td>Frederick County, MD</td>\n",
873
+ " <td>24021</td>\n",
874
+ " <td>2005</td>\n",
875
+ " <td>Drug poisonings (overdose) Undetermined (Y10-Y14)</td>\n",
876
+ " <td>13</td>\n",
877
+ " </tr>\n",
878
+ " <tr>\n",
879
+ " <th>22426</th>\n",
880
+ " <td>Boyd County, KY</td>\n",
881
+ " <td>21019</td>\n",
882
+ " <td>2008</td>\n",
883
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
884
+ " <td>24</td>\n",
885
+ " </tr>\n",
886
+ " </tbody>\n",
887
+ "</table>\n",
888
+ "</div>"
889
+ ],
890
+ "text/plain": [
891
+ " County County Code Year \\\n",
892
+ "30939 Wabash County, IN 18169 2010 \n",
893
+ "36770 Cayuga County, NY 36011 2011 \n",
894
+ "2317 Passaic County, NJ 34031 2003 \n",
895
+ "9869 Frederick County, MD 24021 2005 \n",
896
+ "22426 Boyd County, KY 21019 2008 \n",
897
+ "\n",
898
+ " Drug/Alcohol Induced Cause Deaths \n",
899
+ "30939 Drug poisonings (overdose) Unintentional (X40-... 10 \n",
900
+ "36770 Drug poisonings (overdose) Unintentional (X40-... 10 \n",
901
+ "2317 Drug poisonings (overdose) Unintentional (X40-... 28 \n",
902
+ "9869 Drug poisonings (overdose) Undetermined (Y10-Y14) 13 \n",
903
+ "22426 Drug poisonings (overdose) Unintentional (X40-... 24 "
904
+ ]
905
+ },
906
+ "execution_count": 16,
907
+ "metadata": {},
908
+ "output_type": "execute_result"
909
+ }
910
+ ],
911
+ "source": [
912
+ "df3.sample(5)"
913
+ ]
914
+ },
915
+ {
916
+ "cell_type": "code",
917
+ "execution_count": 17,
918
+ "metadata": {},
919
+ "outputs": [],
920
+ "source": [
921
+ "# renaming columns\n",
922
+ "df3.rename(\n",
923
+ " columns={\"Drug/Alcohol Induced Cause\": \"Cause\", \"County Code\": \"County_Code\"},\n",
924
+ " inplace=True,\n",
925
+ ")"
926
+ ]
927
+ },
928
+ {
929
+ "cell_type": "code",
930
+ "execution_count": 18,
931
+ "metadata": {},
932
+ "outputs": [],
933
+ "source": [
934
+ "# use fips file to generate proper county name and state\n",
935
+ "fips = pd.read_csv(\"../.01_Data/01_Raw/county_fips.csv\")\n",
936
+ "fips[\"countyfips\"] = fips[\"countyfips\"].astype(str).str.zfill(5)"
937
+ ]
938
+ },
939
+ {
940
+ "cell_type": "code",
941
+ "execution_count": 19,
942
+ "metadata": {},
943
+ "outputs": [
944
+ {
945
+ "data": {
946
+ "text/html": [
947
+ "<div>\n",
948
+ "<style scoped>\n",
949
+ " .dataframe tbody tr th:only-of-type {\n",
950
+ " vertical-align: middle;\n",
951
+ " }\n",
952
+ "\n",
953
+ " .dataframe tbody tr th {\n",
954
+ " vertical-align: top;\n",
955
+ " }\n",
956
+ "\n",
957
+ " .dataframe thead th {\n",
958
+ " text-align: right;\n",
959
+ " }\n",
960
+ "</style>\n",
961
+ "<table border=\"1\" class=\"dataframe\">\n",
962
+ " <thead>\n",
963
+ " <tr style=\"text-align: right;\">\n",
964
+ " <th></th>\n",
965
+ " <th>County</th>\n",
966
+ " <th>County_Code</th>\n",
967
+ " <th>Year</th>\n",
968
+ " <th>Cause</th>\n",
969
+ " <th>Deaths</th>\n",
970
+ " <th>BUYER_COUNTY</th>\n",
971
+ " <th>BUYER_STATE</th>\n",
972
+ " <th>countyfips</th>\n",
973
+ " <th>_merge</th>\n",
974
+ " </tr>\n",
975
+ " </thead>\n",
976
+ " <tbody>\n",
977
+ " <tr>\n",
978
+ " <th>1799</th>\n",
979
+ " <td>Hidalgo County, TX</td>\n",
980
+ " <td>48215</td>\n",
981
+ " <td>2005</td>\n",
982
+ " <td>All other drug-induced causes</td>\n",
983
+ " <td>10</td>\n",
984
+ " <td>HIDALGO</td>\n",
985
+ " <td>TX</td>\n",
986
+ " <td>48215</td>\n",
987
+ " <td>both</td>\n",
988
+ " </tr>\n",
989
+ " <tr>\n",
990
+ " <th>9215</th>\n",
991
+ " <td>Greenville County, SC</td>\n",
992
+ " <td>45045</td>\n",
993
+ " <td>2014</td>\n",
994
+ " <td>Drug poisonings (overdose) Suicide (X60-X64)</td>\n",
995
+ " <td>10</td>\n",
996
+ " <td>GREENVILLE</td>\n",
997
+ " <td>SC</td>\n",
998
+ " <td>45045</td>\n",
999
+ " <td>both</td>\n",
1000
+ " </tr>\n",
1001
+ " <tr>\n",
1002
+ " <th>2843</th>\n",
1003
+ " <td>St. Clair County, IL</td>\n",
1004
+ " <td>17163</td>\n",
1005
+ " <td>2007</td>\n",
1006
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1007
+ " <td>15</td>\n",
1008
+ " <td>SAINT CLAIR</td>\n",
1009
+ " <td>IL</td>\n",
1010
+ " <td>17163</td>\n",
1011
+ " <td>both</td>\n",
1012
+ " </tr>\n",
1013
+ " <tr>\n",
1014
+ " <th>1063</th>\n",
1015
+ " <td>Northampton County, PA</td>\n",
1016
+ " <td>42095</td>\n",
1017
+ " <td>2004</td>\n",
1018
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1019
+ " <td>16</td>\n",
1020
+ " <td>NORTHAMPTON</td>\n",
1021
+ " <td>PA</td>\n",
1022
+ " <td>42095</td>\n",
1023
+ " <td>both</td>\n",
1024
+ " </tr>\n",
1025
+ " <tr>\n",
1026
+ " <th>4368</th>\n",
1027
+ " <td>Newton County, GA</td>\n",
1028
+ " <td>13217</td>\n",
1029
+ " <td>2009</td>\n",
1030
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1031
+ " <td>13</td>\n",
1032
+ " <td>NEWTON</td>\n",
1033
+ " <td>GA</td>\n",
1034
+ " <td>13217</td>\n",
1035
+ " <td>both</td>\n",
1036
+ " </tr>\n",
1037
+ " </tbody>\n",
1038
+ "</table>\n",
1039
+ "</div>"
1040
+ ],
1041
+ "text/plain": [
1042
+ " County County_Code Year \\\n",
1043
+ "1799 Hidalgo County, TX 48215 2005 \n",
1044
+ "9215 Greenville County, SC 45045 2014 \n",
1045
+ "2843 St. Clair County, IL 17163 2007 \n",
1046
+ "1063 Northampton County, PA 42095 2004 \n",
1047
+ "4368 Newton County, GA 13217 2009 \n",
1048
+ "\n",
1049
+ " Cause Deaths BUYER_COUNTY \\\n",
1050
+ "1799 All other drug-induced causes 10 HIDALGO \n",
1051
+ "9215 Drug poisonings (overdose) Suicide (X60-X64) 10 GREENVILLE \n",
1052
+ "2843 Drug poisonings (overdose) Unintentional (X40-... 15 SAINT CLAIR \n",
1053
+ "1063 Drug poisonings (overdose) Unintentional (X40-... 16 NORTHAMPTON \n",
1054
+ "4368 Drug poisonings (overdose) Unintentional (X40-... 13 NEWTON \n",
1055
+ "\n",
1056
+ " BUYER_STATE countyfips _merge \n",
1057
+ "1799 TX 48215 both \n",
1058
+ "9215 SC 45045 both \n",
1059
+ "2843 IL 17163 both \n",
1060
+ "1063 PA 42095 both \n",
1061
+ "4368 GA 13217 both "
1062
+ ]
1063
+ },
1064
+ "execution_count": 19,
1065
+ "metadata": {},
1066
+ "output_type": "execute_result"
1067
+ }
1068
+ ],
1069
+ "source": [
1070
+ "# merge with fips\n",
1071
+ "# performing left join to get the county names\n",
1072
+ "df4 = pd.merge(\n",
1073
+ " df3,\n",
1074
+ " fips,\n",
1075
+ " how=\"left\",\n",
1076
+ " left_on=\"County_Code\",\n",
1077
+ " right_on=\"countyfips\",\n",
1078
+ " validate=\"m:1\",\n",
1079
+ " indicator=True,\n",
1080
+ ")\n",
1081
+ "df4.sample(5)"
1082
+ ]
1083
+ },
1084
+ {
1085
+ "cell_type": "code",
1086
+ "execution_count": 20,
1087
+ "metadata": {},
1088
+ "outputs": [
1089
+ {
1090
+ "data": {
1091
+ "text/plain": [
1092
+ "_merge\n",
1093
+ "both 10432\n",
1094
+ "left_only 0\n",
1095
+ "right_only 0\n",
1096
+ "Name: count, dtype: int64"
1097
+ ]
1098
+ },
1099
+ "execution_count": 20,
1100
+ "metadata": {},
1101
+ "output_type": "execute_result"
1102
+ }
1103
+ ],
1104
+ "source": [
1105
+ "# Validate if merge went well\n",
1106
+ "df4[\"_merge\"].value_counts()"
1107
+ ]
1108
+ },
1109
+ {
1110
+ "cell_type": "code",
1111
+ "execution_count": 21,
1112
+ "metadata": {},
1113
+ "outputs": [],
1114
+ "source": [
1115
+ "# select required colums\n",
1116
+ "df5 = df4[[\"BUYER_STATE\", \"BUYER_COUNTY\", \"County_Code\", \"Year\", \"Cause\", \"Deaths\"]]\n",
1117
+ "\n",
1118
+ "# rename columns\n",
1119
+ "df5 = df5.rename(columns={\"BUYER_COUNTY\": \"County\", \"BUYER_STATE\": \"State_Code\"})"
1120
+ ]
1121
+ },
1122
+ {
1123
+ "cell_type": "code",
1124
+ "execution_count": 22,
1125
+ "metadata": {},
1126
+ "outputs": [
1127
+ {
1128
+ "data": {
1129
+ "text/html": [
1130
+ "<div>\n",
1131
+ "<style scoped>\n",
1132
+ " .dataframe tbody tr th:only-of-type {\n",
1133
+ " vertical-align: middle;\n",
1134
+ " }\n",
1135
+ "\n",
1136
+ " .dataframe tbody tr th {\n",
1137
+ " vertical-align: top;\n",
1138
+ " }\n",
1139
+ "\n",
1140
+ " .dataframe thead th {\n",
1141
+ " text-align: right;\n",
1142
+ " }\n",
1143
+ "</style>\n",
1144
+ "<table border=\"1\" class=\"dataframe\">\n",
1145
+ " <thead>\n",
1146
+ " <tr style=\"text-align: right;\">\n",
1147
+ " <th></th>\n",
1148
+ " <th>State_Code</th>\n",
1149
+ " <th>County</th>\n",
1150
+ " <th>County_Code</th>\n",
1151
+ " <th>Year</th>\n",
1152
+ " <th>Cause</th>\n",
1153
+ " <th>Deaths</th>\n",
1154
+ " </tr>\n",
1155
+ " </thead>\n",
1156
+ " <tbody>\n",
1157
+ " <tr>\n",
1158
+ " <th>2201</th>\n",
1159
+ " <td>MI</td>\n",
1160
+ " <td>BERRIEN</td>\n",
1161
+ " <td>26021</td>\n",
1162
+ " <td>2006</td>\n",
1163
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1164
+ " <td>21</td>\n",
1165
+ " </tr>\n",
1166
+ " <tr>\n",
1167
+ " <th>3238</th>\n",
1168
+ " <td>TN</td>\n",
1169
+ " <td>BRADLEY</td>\n",
1170
+ " <td>47011</td>\n",
1171
+ " <td>2007</td>\n",
1172
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1173
+ " <td>23</td>\n",
1174
+ " </tr>\n",
1175
+ " <tr>\n",
1176
+ " <th>8909</th>\n",
1177
+ " <td>MS</td>\n",
1178
+ " <td>MADISON</td>\n",
1179
+ " <td>28089</td>\n",
1180
+ " <td>2014</td>\n",
1181
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1182
+ " <td>12</td>\n",
1183
+ " </tr>\n",
1184
+ " <tr>\n",
1185
+ " <th>7578</th>\n",
1186
+ " <td>AZ</td>\n",
1187
+ " <td>MARICOPA</td>\n",
1188
+ " <td>04013</td>\n",
1189
+ " <td>2013</td>\n",
1190
+ " <td>Drug poisonings (overdose) Undetermined (Y10-Y14)</td>\n",
1191
+ " <td>89</td>\n",
1192
+ " </tr>\n",
1193
+ " <tr>\n",
1194
+ " <th>5624</th>\n",
1195
+ " <td>SC</td>\n",
1196
+ " <td>OCONEE</td>\n",
1197
+ " <td>45073</td>\n",
1198
+ " <td>2010</td>\n",
1199
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1200
+ " <td>16</td>\n",
1201
+ " </tr>\n",
1202
+ " </tbody>\n",
1203
+ "</table>\n",
1204
+ "</div>"
1205
+ ],
1206
+ "text/plain": [
1207
+ " State_Code County County_Code Year \\\n",
1208
+ "2201 MI BERRIEN 26021 2006 \n",
1209
+ "3238 TN BRADLEY 47011 2007 \n",
1210
+ "8909 MS MADISON 28089 2014 \n",
1211
+ "7578 AZ MARICOPA 04013 2013 \n",
1212
+ "5624 SC OCONEE 45073 2010 \n",
1213
+ "\n",
1214
+ " Cause Deaths \n",
1215
+ "2201 Drug poisonings (overdose) Unintentional (X40-... 21 \n",
1216
+ "3238 Drug poisonings (overdose) Unintentional (X40-... 23 \n",
1217
+ "8909 Drug poisonings (overdose) Unintentional (X40-... 12 \n",
1218
+ "7578 Drug poisonings (overdose) Undetermined (Y10-Y14) 89 \n",
1219
+ "5624 Drug poisonings (overdose) Unintentional (X40-... 16 "
1220
+ ]
1221
+ },
1222
+ "execution_count": 22,
1223
+ "metadata": {},
1224
+ "output_type": "execute_result"
1225
+ }
1226
+ ],
1227
+ "source": [
1228
+ "df5.sample(5)"
1229
+ ]
1230
+ },
1231
+ {
1232
+ "cell_type": "code",
1233
+ "execution_count": 23,
1234
+ "metadata": {},
1235
+ "outputs": [
1236
+ {
1237
+ "data": {
1238
+ "text/html": [
1239
+ "<div>\n",
1240
+ "<style scoped>\n",
1241
+ " .dataframe tbody tr th:only-of-type {\n",
1242
+ " vertical-align: middle;\n",
1243
+ " }\n",
1244
+ "\n",
1245
+ " .dataframe tbody tr th {\n",
1246
+ " vertical-align: top;\n",
1247
+ " }\n",
1248
+ "\n",
1249
+ " .dataframe thead th {\n",
1250
+ " text-align: right;\n",
1251
+ " }\n",
1252
+ "</style>\n",
1253
+ "<table border=\"1\" class=\"dataframe\">\n",
1254
+ " <thead>\n",
1255
+ " <tr style=\"text-align: right;\">\n",
1256
+ " <th></th>\n",
1257
+ " <th>state</th>\n",
1258
+ " <th>abbrev</th>\n",
1259
+ " <th>code</th>\n",
1260
+ " </tr>\n",
1261
+ " </thead>\n",
1262
+ " <tbody>\n",
1263
+ " <tr>\n",
1264
+ " <th>13</th>\n",
1265
+ " <td>Illinois</td>\n",
1266
+ " <td>Ill.</td>\n",
1267
+ " <td>IL</td>\n",
1268
+ " </tr>\n",
1269
+ " <tr>\n",
1270
+ " <th>40</th>\n",
1271
+ " <td>South Carolina</td>\n",
1272
+ " <td>S.C.</td>\n",
1273
+ " <td>SC</td>\n",
1274
+ " </tr>\n",
1275
+ " <tr>\n",
1276
+ " <th>10</th>\n",
1277
+ " <td>Georgia</td>\n",
1278
+ " <td>Ga.</td>\n",
1279
+ " <td>GA</td>\n",
1280
+ " </tr>\n",
1281
+ " <tr>\n",
1282
+ " <th>34</th>\n",
1283
+ " <td>North Dakota</td>\n",
1284
+ " <td>N.D.</td>\n",
1285
+ " <td>ND</td>\n",
1286
+ " </tr>\n",
1287
+ " <tr>\n",
1288
+ " <th>38</th>\n",
1289
+ " <td>Pennsylvania</td>\n",
1290
+ " <td>Pa.</td>\n",
1291
+ " <td>PA</td>\n",
1292
+ " </tr>\n",
1293
+ " </tbody>\n",
1294
+ "</table>\n",
1295
+ "</div>"
1296
+ ],
1297
+ "text/plain": [
1298
+ " state abbrev code\n",
1299
+ "13 Illinois Ill. IL\n",
1300
+ "40 South Carolina S.C. SC\n",
1301
+ "10 Georgia Ga. GA\n",
1302
+ "34 North Dakota N.D. ND\n",
1303
+ "38 Pennsylvania Pa. PA"
1304
+ ]
1305
+ },
1306
+ "execution_count": 23,
1307
+ "metadata": {},
1308
+ "output_type": "execute_result"
1309
+ }
1310
+ ],
1311
+ "source": [
1312
+ "# Add state names to maitain consistency with population data\n",
1313
+ "abbreviations = pd.read_csv(\"../.01_Data/01_Raw/state_abbreviations.csv\")\n",
1314
+ "abbreviations.sample(5)"
1315
+ ]
1316
+ },
1317
+ {
1318
+ "cell_type": "code",
1319
+ "execution_count": 24,
1320
+ "metadata": {},
1321
+ "outputs": [],
1322
+ "source": [
1323
+ "# rename colums to match with the main dataframe\n",
1324
+ "abbreviations = abbreviations.rename(\n",
1325
+ " columns={\n",
1326
+ " \"state\": \"State\",\n",
1327
+ " \"code\": \"State_Code\",\n",
1328
+ " }\n",
1329
+ ")"
1330
+ ]
1331
+ },
1332
+ {
1333
+ "cell_type": "code",
1334
+ "execution_count": 25,
1335
+ "metadata": {},
1336
+ "outputs": [
1337
+ {
1338
+ "data": {
1339
+ "text/html": [
1340
+ "<div>\n",
1341
+ "<style scoped>\n",
1342
+ " .dataframe tbody tr th:only-of-type {\n",
1343
+ " vertical-align: middle;\n",
1344
+ " }\n",
1345
+ "\n",
1346
+ " .dataframe tbody tr th {\n",
1347
+ " vertical-align: top;\n",
1348
+ " }\n",
1349
+ "\n",
1350
+ " .dataframe thead th {\n",
1351
+ " text-align: right;\n",
1352
+ " }\n",
1353
+ "</style>\n",
1354
+ "<table border=\"1\" class=\"dataframe\">\n",
1355
+ " <thead>\n",
1356
+ " <tr style=\"text-align: right;\">\n",
1357
+ " <th></th>\n",
1358
+ " <th>State_Code</th>\n",
1359
+ " <th>County</th>\n",
1360
+ " <th>County_Code</th>\n",
1361
+ " <th>Year</th>\n",
1362
+ " <th>Cause</th>\n",
1363
+ " <th>Deaths</th>\n",
1364
+ " <th>State</th>\n",
1365
+ " <th>_merge</th>\n",
1366
+ " </tr>\n",
1367
+ " </thead>\n",
1368
+ " <tbody>\n",
1369
+ " <tr>\n",
1370
+ " <th>6372</th>\n",
1371
+ " <td>OH</td>\n",
1372
+ " <td>DELAWARE</td>\n",
1373
+ " <td>39041</td>\n",
1374
+ " <td>2011</td>\n",
1375
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1376
+ " <td>11</td>\n",
1377
+ " <td>Ohio</td>\n",
1378
+ " <td>both</td>\n",
1379
+ " </tr>\n",
1380
+ " <tr>\n",
1381
+ " <th>5339</th>\n",
1382
+ " <td>MI</td>\n",
1383
+ " <td>WASHTENAW</td>\n",
1384
+ " <td>26161</td>\n",
1385
+ " <td>2010</td>\n",
1386
+ " <td>Drug poisonings (overdose) Undetermined (Y10-Y14)</td>\n",
1387
+ " <td>19</td>\n",
1388
+ " <td>Michigan</td>\n",
1389
+ " <td>both</td>\n",
1390
+ " </tr>\n",
1391
+ " <tr>\n",
1392
+ " <th>8433</th>\n",
1393
+ " <td>WV</td>\n",
1394
+ " <td>WAYNE</td>\n",
1395
+ " <td>54099</td>\n",
1396
+ " <td>2013</td>\n",
1397
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1398
+ " <td>17</td>\n",
1399
+ " <td>West Virginia</td>\n",
1400
+ " <td>both</td>\n",
1401
+ " </tr>\n",
1402
+ " <tr>\n",
1403
+ " <th>4737</th>\n",
1404
+ " <td>OR</td>\n",
1405
+ " <td>CLACKAMAS</td>\n",
1406
+ " <td>41005</td>\n",
1407
+ " <td>2009</td>\n",
1408
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1409
+ " <td>32</td>\n",
1410
+ " <td>Oregon</td>\n",
1411
+ " <td>both</td>\n",
1412
+ " </tr>\n",
1413
+ " <tr>\n",
1414
+ " <th>93</th>\n",
1415
+ " <td>CO</td>\n",
1416
+ " <td>LARIMER</td>\n",
1417
+ " <td>08069</td>\n",
1418
+ " <td>2003</td>\n",
1419
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1420
+ " <td>13</td>\n",
1421
+ " <td>Colorado</td>\n",
1422
+ " <td>both</td>\n",
1423
+ " </tr>\n",
1424
+ " </tbody>\n",
1425
+ "</table>\n",
1426
+ "</div>"
1427
+ ],
1428
+ "text/plain": [
1429
+ " State_Code County County_Code Year \\\n",
1430
+ "6372 OH DELAWARE 39041 2011 \n",
1431
+ "5339 MI WASHTENAW 26161 2010 \n",
1432
+ "8433 WV WAYNE 54099 2013 \n",
1433
+ "4737 OR CLACKAMAS 41005 2009 \n",
1434
+ "93 CO LARIMER 08069 2003 \n",
1435
+ "\n",
1436
+ " Cause Deaths \\\n",
1437
+ "6372 Drug poisonings (overdose) Unintentional (X40-... 11 \n",
1438
+ "5339 Drug poisonings (overdose) Undetermined (Y10-Y14) 19 \n",
1439
+ "8433 Drug poisonings (overdose) Unintentional (X40-... 17 \n",
1440
+ "4737 Drug poisonings (overdose) Unintentional (X40-... 32 \n",
1441
+ "93 Drug poisonings (overdose) Unintentional (X40-... 13 \n",
1442
+ "\n",
1443
+ " State _merge \n",
1444
+ "6372 Ohio both \n",
1445
+ "5339 Michigan both \n",
1446
+ "8433 West Virginia both \n",
1447
+ "4737 Oregon both \n",
1448
+ "93 Colorado both "
1449
+ ]
1450
+ },
1451
+ "execution_count": 25,
1452
+ "metadata": {},
1453
+ "output_type": "execute_result"
1454
+ }
1455
+ ],
1456
+ "source": [
1457
+ "# Merge\n",
1458
+ "df6 = pd.merge(\n",
1459
+ " df5,\n",
1460
+ " abbreviations[[\"State\", \"State_Code\"]],\n",
1461
+ " how=\"left\",\n",
1462
+ " on=\"State_Code\",\n",
1463
+ " validate=\"m:1\",\n",
1464
+ " indicator=True,\n",
1465
+ ")\n",
1466
+ "df6.sample(5)"
1467
+ ]
1468
+ },
1469
+ {
1470
+ "cell_type": "code",
1471
+ "execution_count": 26,
1472
+ "metadata": {},
1473
+ "outputs": [
1474
+ {
1475
+ "data": {
1476
+ "text/plain": [
1477
+ "_merge\n",
1478
+ "both 10432\n",
1479
+ "left_only 0\n",
1480
+ "right_only 0\n",
1481
+ "Name: count, dtype: int64"
1482
+ ]
1483
+ },
1484
+ "execution_count": 26,
1485
+ "metadata": {},
1486
+ "output_type": "execute_result"
1487
+ }
1488
+ ],
1489
+ "source": [
1490
+ "# Validate if merge went well\n",
1491
+ "df6[\"_merge\"].value_counts()"
1492
+ ]
1493
+ },
1494
+ {
1495
+ "cell_type": "markdown",
1496
+ "metadata": {},
1497
+ "source": [
1498
+ "In script file we dont need the merge indicator column, so it will not be used there"
1499
+ ]
1500
+ },
1501
+ {
1502
+ "cell_type": "code",
1503
+ "execution_count": 27,
1504
+ "metadata": {},
1505
+ "outputs": [
1506
+ {
1507
+ "data": {
1508
+ "text/html": [
1509
+ "<div>\n",
1510
+ "<style scoped>\n",
1511
+ " .dataframe tbody tr th:only-of-type {\n",
1512
+ " vertical-align: middle;\n",
1513
+ " }\n",
1514
+ "\n",
1515
+ " .dataframe tbody tr th {\n",
1516
+ " vertical-align: top;\n",
1517
+ " }\n",
1518
+ "\n",
1519
+ " .dataframe thead th {\n",
1520
+ " text-align: right;\n",
1521
+ " }\n",
1522
+ "</style>\n",
1523
+ "<table border=\"1\" class=\"dataframe\">\n",
1524
+ " <thead>\n",
1525
+ " <tr style=\"text-align: right;\">\n",
1526
+ " <th></th>\n",
1527
+ " <th>State</th>\n",
1528
+ " <th>State_Code</th>\n",
1529
+ " <th>County</th>\n",
1530
+ " <th>County_Code</th>\n",
1531
+ " <th>Year</th>\n",
1532
+ " <th>Cause</th>\n",
1533
+ " <th>Deaths</th>\n",
1534
+ " </tr>\n",
1535
+ " </thead>\n",
1536
+ " <tbody>\n",
1537
+ " <tr>\n",
1538
+ " <th>2398</th>\n",
1539
+ " <td>Ohio</td>\n",
1540
+ " <td>OH</td>\n",
1541
+ " <td>TRUMBULL</td>\n",
1542
+ " <td>39155</td>\n",
1543
+ " <td>2006</td>\n",
1544
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1545
+ " <td>30</td>\n",
1546
+ " </tr>\n",
1547
+ " <tr>\n",
1548
+ " <th>5703</th>\n",
1549
+ " <td>Utah</td>\n",
1550
+ " <td>UT</td>\n",
1551
+ " <td>DAVIS</td>\n",
1552
+ " <td>49011</td>\n",
1553
+ " <td>2010</td>\n",
1554
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1555
+ " <td>22</td>\n",
1556
+ " </tr>\n",
1557
+ " <tr>\n",
1558
+ " <th>10208</th>\n",
1559
+ " <td>South Carolina</td>\n",
1560
+ " <td>SC</td>\n",
1561
+ " <td>AIKEN</td>\n",
1562
+ " <td>45003</td>\n",
1563
+ " <td>2015</td>\n",
1564
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1565
+ " <td>30</td>\n",
1566
+ " </tr>\n",
1567
+ " <tr>\n",
1568
+ " <th>242</th>\n",
1569
+ " <td>Maryland</td>\n",
1570
+ " <td>MD</td>\n",
1571
+ " <td>PRINCE GEORGES</td>\n",
1572
+ " <td>24033</td>\n",
1573
+ " <td>2003</td>\n",
1574
+ " <td>Drug poisonings (overdose) Unintentional (X40-...</td>\n",
1575
+ " <td>14</td>\n",
1576
+ " </tr>\n",
1577
+ " <tr>\n",
1578
+ " <th>1250</th>\n",
1579
+ " <td>California</td>\n",
1580
+ " <td>CA</td>\n",
1581
+ " <td>MARIN</td>\n",
1582
+ " <td>06041</td>\n",
1583
+ " <td>2005</td>\n",
1584
+ " <td>Drug poisonings (overdose) Undetermined (Y10-Y14)</td>\n",
1585
+ " <td>16</td>\n",
1586
+ " </tr>\n",
1587
+ " </tbody>\n",
1588
+ "</table>\n",
1589
+ "</div>"
1590
+ ],
1591
+ "text/plain": [
1592
+ " State State_Code County County_Code Year \\\n",
1593
+ "2398 Ohio OH TRUMBULL 39155 2006 \n",
1594
+ "5703 Utah UT DAVIS 49011 2010 \n",
1595
+ "10208 South Carolina SC AIKEN 45003 2015 \n",
1596
+ "242 Maryland MD PRINCE GEORGES 24033 2003 \n",
1597
+ "1250 California CA MARIN 06041 2005 \n",
1598
+ "\n",
1599
+ " Cause Deaths \n",
1600
+ "2398 Drug poisonings (overdose) Unintentional (X40-... 30 \n",
1601
+ "5703 Drug poisonings (overdose) Unintentional (X40-... 22 \n",
1602
+ "10208 Drug poisonings (overdose) Unintentional (X40-... 30 \n",
1603
+ "242 Drug poisonings (overdose) Unintentional (X40-... 14 \n",
1604
+ "1250 Drug poisonings (overdose) Undetermined (Y10-Y14) 16 "
1605
+ ]
1606
+ },
1607
+ "execution_count": 27,
1608
+ "metadata": {},
1609
+ "output_type": "execute_result"
1610
+ }
1611
+ ],
1612
+ "source": [
1613
+ "# reorder columns to match population data\n",
1614
+ "df6 = df6[[\"State\", \"State_Code\", \"County\", \"County_Code\", \"Year\", \"Cause\", \"Deaths\"]]\n",
1615
+ "df6.sample(5)"
1616
+ ]
1617
+ }
1618
+ ],
1619
+ "metadata": {
1620
+ "kernelspec": {
1621
+ "display_name": "base",
1622
+ "language": "python",
1623
+ "name": "python3"
1624
+ },
1625
+ "language_info": {
1626
+ "codemirror_mode": {
1627
+ "name": "ipython",
1628
+ "version": 3
1629
+ },
1630
+ "file_extension": ".py",
1631
+ "mimetype": "text/x-python",
1632
+ "name": "python",
1633
+ "nbconvert_exporter": "python",
1634
+ "pygments_lexer": "ipython3",
1635
+ "version": "3.11.5"
1636
+ }
1637
+ },
1638
+ "nbformat": 4,
1639
+ "nbformat_minor": 2
1640
+ }
02_Codes/04_mortality_script.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Impoting required packages
2
+ import pandas as pd
3
+ import numpy as np
4
+ import zipfile
5
+
6
+ # setting default option
7
+ pd.set_option("mode.copy_on_write", True)
8
+
9
+ # ------------------------------------------
10
+ # reading the files
11
+ z = zipfile.ZipFile(".01_Data/01_Raw/raw_mortality.zip")
12
+ fips = pd.read_csv(".01_Data/01_Raw/county_fips.csv")
13
+ abbreviations = pd.read_csv(".01_Data/01_Raw/state_abbreviations.csv")
14
+
15
+ # extracting list of files from Zip folder to read
16
+ # using files starting with "Underlying" so as to ignore system files
17
+ file_list = sorted([f for f in z.namelist() if f.startswith("Underlying")])
18
+
19
+
20
+ # ------------------------------------------
21
+ # read data selected files and append to list
22
+ df_list = []
23
+ for file in file_list:
24
+ # read individual files
25
+ df_temp = pd.read_csv(z.open(file), sep="\t")
26
+
27
+ # drop the notes columns and remove rows with null values in County column
28
+ df_temp.drop(columns=["Notes"], inplace=True)
29
+ df_temp.dropna(subset=["County"], inplace=True)
30
+
31
+ # add the cleaned temp Df to the main list
32
+ df_list.append(df_temp)
33
+
34
+ # ------------------------------------------
35
+ # create the dataframe
36
+ df = pd.concat(df_list, ignore_index=True)
37
+
38
+ # ------------------------------------------
39
+ # Correcting Data Types for columns
40
+ df2 = df.copy()
41
+
42
+ # Pad county code with 0 for consistency with other data sets
43
+ df2["County Code"] = df2["County Code"].astype(int).astype(str).str.zfill(5)
44
+
45
+ # padding fips to have consistency
46
+ fips["countyfips"] = fips["countyfips"].astype(str).str.zfill(5)
47
+
48
+ # Convert Year to Int
49
+ df2["Year"] = df2["Year"].astype(int)
50
+
51
+ # Convert Deaths to Int
52
+ df2["Deaths"] = df2["Deaths"].replace("Missing", np.nan)
53
+ df2["Deaths"] = (
54
+ df2["Deaths"].astype(float).astype("Int64")
55
+ ) # making it as int64 so that we retain null values for later analysis
56
+
57
+ # ------------------------------------------
58
+
59
+ # Store only the rows related drugs, modify this list later if required
60
+ required_causes = [
61
+ "Drug poisonings (overdose) Unintentional (X40-X44)",
62
+ "All other drug-induced causes",
63
+ "Drug poisonings (overdose) Homicide (X85)",
64
+ "Drug poisonings (overdose) Suicide (X60-X64)",
65
+ "Drug poisonings (overdose) Undetermined (Y10-Y14)",
66
+ ]
67
+
68
+ # ------------------------------------------------------
69
+ # create and optimize subset data
70
+ df3 = df2[df2["Drug/Alcohol Induced Cause"].isin(required_causes)]
71
+
72
+ # remove extra columns
73
+ df3.drop(columns=["Year Code", "Drug/Alcohol Induced Cause Code"], inplace=True)
74
+
75
+ # renaming columns
76
+ df3.rename(
77
+ columns={"Drug/Alcohol Induced Cause": "Cause", "County Code": "County_Code"},
78
+ inplace=True,
79
+ )
80
+
81
+ # ------------------------------------------------------
82
+ # mapping with fips for proper county names and state name
83
+ df4 = pd.merge(
84
+ df3,
85
+ fips,
86
+ how="left",
87
+ left_on="County_Code",
88
+ right_on="countyfips",
89
+ validate="m:1",
90
+ indicator=True,
91
+ )
92
+
93
+ # --------------------------------------------------------
94
+ # Prepare final DF for saving
95
+ # select required colums
96
+ df5 = df4[["BUYER_STATE", "BUYER_COUNTY", "County_Code", "Year", "Cause", "Deaths"]]
97
+
98
+ # rename columns
99
+ df5 = df5.rename(columns={"BUYER_COUNTY": "County", "BUYER_STATE": "State_Code"})
100
+
101
+ abbreviations = abbreviations.rename(
102
+ columns={
103
+ "state": "State",
104
+ "code": "State_Code",
105
+ }
106
+ )
107
+
108
+ # merge with abbreviations
109
+ df6 = pd.merge(
110
+ df5,
111
+ abbreviations[["State", "State_Code"]],
112
+ how="left",
113
+ on="State_Code",
114
+ validate="m:1",
115
+ )
116
+
117
+ # reorder columns to match population data
118
+ df6 = df6[["State", "State_Code", "County", "County_Code", "Year", "Cause", "Deaths"]]
119
+
120
+ # ------------------------------------------
121
+ # Writing to Parquet
122
+ df6.to_parquet(".01_Data/02_Processed/02_Mortality.parquet", index=False)