2424 },
2525 {
2626 "cell_type" : " code" ,
27- "execution_count" : 1 ,
27+ "execution_count" : 4 ,
28+ "metadata" : {
29+ "id" : " HhQ_FIqhjHEG"
30+ },
31+ "outputs" : [],
32+ "source" : [
33+ " #export \n " ,
34+ " \n " ,
35+ " #These are the libraries used by every script. The scripts WILL NOT run without them. \n " ,
36+ " from VitalSigns.acsDownload import retrieve_acs_data\n " ,
37+ " from dataplay.merge import mergeDatasets\n " ,
38+ " from dataplay.intaker import Intake \n " ,
39+ " from IPython.display import clear_output\n " ,
40+ " import pandas as pd\n " ,
41+ " import geopandas as gpd\n " ,
42+ " import glob\n " ,
43+ " import numpy\n " ,
44+ " import csv"
45+ ]
46+ },
47+ {
48+ "cell_type" : " code" ,
49+ "execution_count" : 35 ,
2850 "metadata" : {
2951 "id" : " c38OYV2HZ65Y"
3052 },
6789 " fi = fi.drop(fi.index[1]) #Remove baltimore City row from fi based on index location - its index location is 1 for both 2010 and 2020 indicators.\n " ,
6890 " fi.loc['Baltimore City'] = bc\n " ,
6991 " \n " ,
70- " return fi"
71- ]
72- },
73- {
74- "cell_type" : " code" ,
75- "execution_count" : null ,
76- "metadata" : {
77- "id" : " HhQ_FIqhjHEG"
78- },
79- "outputs" : [],
80- "source" : [
81- " #export \n " ,
92+ " return fi\n " ,
8293 " \n " ,
83- " #These are the libraries used by every script. The scripts WILL NOT run without them. \n " ,
84- " from VitalSigns.acsDownload import retrieve_acs_data\n " ,
85- " from dataplay.merge import mergeDatasets\n " ,
86- " from dataplay.intaker import Intake \n " ,
87- " from IPython.display import clear_output\n " ,
88- " import pandas as pd\n " ,
89- " import geopandas as gpd\n " ,
90- " import glob\n " ,
91- " import numpy\n " ,
92- " import csv"
94+ " #Add 2010 CSA Names Column\n " ,
95+ " def add_CSA2010(df):\n " ,
96+ " fi = df\n " ,
97+ " CSA_Crosswalk = pd.read_csv(\" https://raw.githubusercontent.com/BNIA/VitalSigns/main/CSA2010_2020.csv\" )\n " ,
98+ " \n " ,
99+ " fi.reset_index(inplace=True)\n " ,
100+ " fi = CSA_Crosswalk.merge(fi, on=\" CSA2020\" , how=\" inner\" )\n " ,
101+ " \n " ,
102+ " return fi\n " ,
103+ " \n " ,
104+ " #Add 2020 CSA Names Column\n " ,
105+ " def add_CSA2020(df):\n " ,
106+ " fi = df\n " ,
107+ " CSA_Crosswalk = pd.read_csv(\" https://raw.githubusercontent.com/BNIA/VitalSigns/main/CSA2010_2020.csv\" )\n " ,
108+ " \n " ,
109+ " fi.reset_index(inplace=True)\n " ,
110+ " fi = CSA_Crosswalk.merge(fi, on=\" CSA2010\" , how=\" inner\" )\n " ,
111+ " \n " ,
112+ " return fi "
93113 ]
94114 },
95115 {
96116 "cell_type" : " code" ,
97- "execution_count" : null ,
117+ "execution_count" : 49 ,
98118 "metadata" : {
99119 "id" : " SyPNNQF8q9nC"
100120 },
105125 " \n " ,
106126 " def createAcsIndicator(state, county, tract, year, tableId,\n " ,
107127 " mergeUrl, merge_left_col, merge_right_col, merge_how, groupBy,\n " ,
108- " aggMethod, method, columnsToInclude, finalFileName=False ):\n " ,
128+ " aggMethod, method, columnsToInclude):\n " ,
109129 " \n " ,
110130 " # Pull the data\n " ,
111131 " df = retrieve_acs_data(state, county, tract, tableId, year)\n " ,
136156 " # Create the indicator\n " ,
137157 " print('Creating Indicator')\n " ,
138158 " resp = method( df, columnsToInclude)\n " ,
139- " print('Indicator Created')\n " ,
140- " if finalFileName:\n " ,
141- " resp.to_csv(finalFileName, quoting=csv.QUOTE_ALL)\n " ,
142- " print('Indicator Saved')\n " ,
159+ " \n " ,
160+ " #Append Missing CSA Column (2010 or 2020)\n " ,
161+ " print(\" Appending Missing CSA Column\" )\n " ,
162+ " if int(year) <=19:\n " ,
163+ " resp = add_CSA2020(resp)\n " ,
164+ " else:\n " ,
165+ " resp = add_CSA2010(resp)\n " ,
143166 " \n " ,
167+ " print('Indicator Created')\n " ,
144168 " return resp"
145169 ]
146170 },
147171 {
148172 "cell_type" : " code" ,
149- "execution_count" : null ,
173+ "execution_count" : 41 ,
150174 "metadata" : {
151175 "id" : " MHRv3nlMg06s"
152176 },
347371 " groupBy = 'CSA2010',\n " ,
348372 " aggMethod= 'sum', \n " ,
349373 " method = hisp,\n " ,
350- " columnsToInclude = [],\n " ,
351- " finalFileName=False)\n " ,
374+ " columnsToInclude = [])\n " ,
352375 " else:\n " ,
353376 " fi_hisp = createAcsIndicator(state = '24', county = '510', tract = '*' , year = chosen_year, tableId = 'B03002',\n " ,
354377 " mergeUrl = 'https://raw.githubusercontent.com/BNIA/VitalSigns/main/CSA2020.csv', \n " ,
358381 " groupBy = 'CSA2020',\n " ,
359382 " aggMethod= 'sum', \n " ,
360383 " method = hisp,\n " ,
361- " columnsToInclude = [],\n " ,
362- " finalFileName=False)\n " ,
384+ " columnsToInclude = [])\n " ,
363385 " \n " ,
364386 " #Column 012E from the Hisp table has a different name on the years prior to 2019. \n " ,
365387 " #This code changes the name of that column automatically for every year prior to 2019.\n " ,
18661888 ],
18671889 "metadata" : {
18681890 "colab" : {
1869- "collapsed_sections" : [],
1870- "name" : " 04_Create_Acs_Indicatorsipynb" ,
18711891 "provenance" : []
18721892 },
18731893 "kernelspec" : {
18951915 },
18961916 "nbformat" : 4 ,
18971917 "nbformat_minor" : 0
1898- }
1918+ }
0 commit comments