Issue 675 & 676: Adding life expectancy and DOE energy burden data (#683)

* Adding two new data sources.
This commit is contained in:
Lucas Merrill Brown 2021-09-15 09:59:28 -05:00 committed by GitHub
commit e94d05882c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 240 additions and 26 deletions

View file

@ -111,15 +111,29 @@
"cell_type": "code",
"execution_count": null,
"id": "d9968187",
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# Analyze one field at a time (useful for setting thresholds)\n",
"field = \"Percent of individuals < 200% Federal Poverty Line\"\n",
"print(cejst_df[field].describe())\n",
"quantile = .8\n",
"print(f\"Quantile at {quantile} is {np.nanquantile(a=cejst_df[field], q=quantile)}\")\n",
"cejst_df[field].hist()"
"\n",
"quantile = 0.8\n",
"\n",
"for field in [\n",
" \"Percent of individuals < 200% Federal Poverty Line\",\n",
" \"Life expectancy (years)\",\n",
" \"Energy burden\",\n",
"]:\n",
" print(f\"\\n~~~~Analysis for field `{field}`~~~~\")\n",
" print(cejst_df[field].describe())\n",
" print(\n",
" f\"\\nThere are {cejst_df[field].isnull().sum() * 100 / len(cejst_df):.2f}% of values missing.\"\n",
" )\n",
" print(\n",
" f\"\\nQuantile at {quantile} is {np.nanquantile(a=cejst_df[field], q=quantile)}\"\n",
" )\n",
" print(cejst_df[field].hist())"
]
},
{
@ -242,7 +256,7 @@
" \"priority_communities_field\",\n",
" # Note: this field only used by indices defined at the census tract level.\n",
" \"other_census_tract_fields_to_keep\",\n",
" ]\n",
" ],\n",
")\n",
"\n",
"# Define the indices used for CEJST scoring (`census_block_group_indices`) as well as comparison\n",
@ -287,11 +301,12 @@
" method_name=\"Score D (25th percentile)\",\n",
" priority_communities_field=\"Score D (top 25th percentile)\",\n",
" other_census_tract_fields_to_keep=[],\n",
" ),\n",
" Index(\n",
" method_name=\"Poverty\",\n",
" priority_communities_field=\"Poverty (Less than 200% of federal poverty line) (top 25th percentile)\",\n",
" other_census_tract_fields_to_keep=[],\n",
" )\n",
" ),\n",
"]\n",
"\n",
"census_tract_indices = [\n",
@ -590,7 +605,7 @@
" ],\n",
" dropna=False,\n",
" )\n",
" \n",
"\n",
" # Run the comparison function on the groups.\n",
" comparison_df = grouped_df.mean().reset_index()\n",
"\n",
@ -638,7 +653,9 @@
" worksheet.set_column(f\"{column_character}:{column_character}\", column_width)\n",
"\n",
" # Add green to red conditional formatting.\n",
" column_ranges = f\"{column_character}2:{column_character}{len(cbg_score_comparison_df)+1}\"\n",
" column_ranges = (\n",
" f\"{column_character}2:{column_character}{len(cbg_score_comparison_df)+1}\"\n",
" )\n",
" worksheet.conditional_format(\n",
" column_ranges,\n",
" # Min: green, max: red.\n",
@ -695,7 +712,7 @@
" output_dir.mkdir(parents=True, exist_ok=True)\n",
" file_path = output_dir / (file_name_part + \".csv\")\n",
" file_path_xlsx = output_dir / (file_name_part + \".xlsx\")\n",
" \n",
"\n",
" cbg_score_comparison_df.to_csv(\n",
" path_or_buf=file_path,\n",
" na_rep=\"\",\n",