Issue 242: Add HOLC Grades to data inputs (#978)

* Add mapping inequality data to data inputs

* Add mapping inequality data to comparison tool
This commit is contained in:
Lucas Merrill Brown 2021-12-04 12:23:01 -05:00 committed by GitHub
commit c5dff6e5f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 317 additions and 15 deletions

View file

@ -3,6 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "71c4acd0",
"metadata": {
"scrolled": true
},
@ -48,6 +49,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2ce3170c",
"metadata": {
"scrolled": true
},
@ -79,6 +81,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8bd39090",
"metadata": {
"scrolled": true
},
@ -105,6 +108,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a251a0fb",
"metadata": {},
"outputs": [],
"source": [
@ -138,6 +142,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e43a9e23",
"metadata": {},
"outputs": [],
"source": [
@ -160,6 +165,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "38c0dc2f",
"metadata": {
"scrolled": false
},
@ -186,8 +192,9 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8c3e462c",
"metadata": {
"scrolled": false
"scrolled": true
},
"outputs": [],
"source": [
@ -215,6 +222,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d8ec43dc",
"metadata": {},
"outputs": [],
"source": [
@ -247,13 +255,43 @@
{
"cell_type": "code",
"execution_count": null,
"id": "81826d29",
"metadata": {},
"outputs": [],
"source": [
"# Load mapping inequality data\n",
"HOLC_FACTORS = [\n",
" field_names.HOLC_GRADE_D_TRACT_20_PERCENT_FIELD,\n",
" field_names.HOLC_GRADE_D_TRACT_50_PERCENT_FIELD,\n",
" field_names.HOLC_GRADE_D_TRACT_75_PERCENT_FIELD,\n",
"]\n",
"mapping_inequality_path = (\n",
" DATA_DIR / \"dataset\" / \"mapping_inequality\" / \"usa.csv\"\n",
")\n",
"mapping_inequality_df = pd.read_csv(\n",
" mapping_inequality_path,\n",
" dtype={ExtractTransformLoad.GEOID_TRACT_FIELD_NAME: \"string\"},\n",
")\n",
"\n",
"mapping_inequality_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "65659c26",
"metadata": {
"scrolled": false
"scrolled": true
},
"outputs": [],
"source": [
"# Join all dataframes that use tracts\n",
"census_tract_dfs = [cejst_df, calenviroscreen_df, persistent_poverty_df]\n",
"census_tract_dfs = [\n",
" cejst_df,\n",
" calenviroscreen_df,\n",
" persistent_poverty_df,\n",
" mapping_inequality_df,\n",
"]\n",
"\n",
"merged_df = functools.reduce(\n",
" lambda left, right: pd.merge(\n",
@ -281,6 +319,23 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2de78f71",
"metadata": {},
"outputs": [],
"source": [
"# Special handling for HOLC.\n",
"# Fill in the null HOLC values as `False`. Otherwise the comparison tool will not run comparisons in states\n",
"# without HOLC scores, and for HOLC, we'd like to see it across the whole US.\n",
"for holc_factor in HOLC_FACTORS:\n",
" merged_df[holc_factor] = merged_df[holc_factor].fillna(False)\n",
"\n",
"merged_df[HOLC_FACTORS].head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "980c0f66",
"metadata": {
"scrolled": true
},
@ -377,6 +432,16 @@
" other_census_tract_fields_to_keep=[],\n",
" ),\n",
" ]\n",
" # Insert indices for each of the HOLC factors.\n",
" # Note: since these involve no renaming, we write them using list comprehension.\n",
" + [\n",
" Index(\n",
" method_name=factor,\n",
" priority_communities_field=factor,\n",
" other_census_tract_fields_to_keep=[],\n",
" )\n",
" for factor in HOLC_FACTORS\n",
" ]\n",
")\n",
"\n",
"\n",
@ -429,6 +494,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4b510cb1",
"metadata": {
"scrolled": true
},
@ -711,6 +777,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2bcbcabf",
"metadata": {},
"outputs": [],
"source": [
@ -816,6 +883,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d1eec560",
"metadata": {
"scrolled": true
},
@ -1014,6 +1082,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "48005fad",
"metadata": {
"scrolled": true
},
@ -1190,6 +1259,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7d095ebd",
"metadata": {},
"outputs": [],
"source": [