Download column order completed (#1077)

* Download column order completed

* Kameron changes

* Lucas and Beth column order changes

* cdc_places update

* passing score

* pandas error

* checkpoint

* score passing

* rounding complete - percentages still showing one decimal

* fixing tests

* fixing percentages

* updating comment

* int percentages! 🎉🎉

* forgot to pass back to df

* passing tests

Co-authored-by: lucasmbrown-usds <lucas.m.brown@omb.eop.gov>
This commit is contained in:
Jorge Escobar 2022-01-13 15:04:16 -05:00 committed by GitHub
parent 98ff4bd9d8
commit d686bb856e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 232 additions and 133 deletions

View file

@ -13,6 +13,15 @@
"score-run" "score-run"
] ]
}, },
{
"name": "Generate Score Post",
"type": "python",
"request": "launch",
"module": "data_pipeline.application",
"args": [
"generate-score-post"
]
},
{ {
"name": "Data Cleanup", "name": "Data Cleanup",
"type": "python", "type": "python",

View file

@ -63,6 +63,17 @@ SCORE_DOWNLOADABLE_ZIP_FILE_PATH = (
# Column subsets # Column subsets
CENSUS_COUNTIES_COLUMNS = ["USPS", "GEOID", "NAME"] CENSUS_COUNTIES_COLUMNS = ["USPS", "GEOID", "NAME"]
# Percent prefixes for rounding
PERCENT_PREFIXES_SUFFIXES = [
"Percent",
"percent",
"Percentage",
"Energy burden",
"loss rate",
"greater than or equal to 18 years",
field_names.PERCENTILE_FIELD_SUFFIX,
]
TILES_ROUND_NUM_DECIMALS = 2 TILES_ROUND_NUM_DECIMALS = 2
# Tiles data: full field name, tile index name # Tiles data: full field name, tile index name
TILES_SCORE_COLUMNS = { TILES_SCORE_COLUMNS = {
@ -191,91 +202,88 @@ DOWNLOADABLE_SCORE_COLUMNS = [
field_names.GEOID_TRACT_FIELD, field_names.GEOID_TRACT_FIELD,
field_names.COUNTY_FIELD, field_names.COUNTY_FIELD,
field_names.STATE_FIELD, field_names.STATE_FIELD,
field_names.THRESHOLD_COUNT,
field_names.SCORE_L_COMMUNITIES, field_names.SCORE_L_COMMUNITIES,
field_names.TOTAL_POP_FIELD, field_names.TOTAL_POP_FIELD,
field_names.FPL_200_SERIES, field_names.FPL_200_SERIES,
field_names.POVERTY_LESS_THAN_200_FPL_FIELD, field_names.EXPECTED_AGRICULTURE_LOSS_RATE_LOW_INCOME_FIELD,
field_names.POVERTY_LESS_THAN_200_FPL_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX,
field_names.EXPECTED_AGRICULTURE_LOSS_RATE_FIELD,
field_names.EXPECTED_AGRICULTURE_LOSS_RATE_FIELD field_names.EXPECTED_AGRICULTURE_LOSS_RATE_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX, + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.EXPECTED_AGRICULTURE_LOSS_RATE_LOW_INCOME_FIELD, field_names.EXPECTED_AGRICULTURE_LOSS_RATE_FIELD,
field_names.EXPECTED_BUILDING_LOSS_RATE_FIELD, field_names.EXPECTED_BUILDING_LOSS_RATE_LOW_INCOME_FIELD,
field_names.EXPECTED_BUILDING_LOSS_RATE_FIELD field_names.EXPECTED_BUILDING_LOSS_RATE_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX, + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.EXPECTED_BUILDING_LOSS_RATE_LOW_INCOME_FIELD, field_names.EXPECTED_BUILDING_LOSS_RATE_FIELD,
field_names.EXPECTED_POPULATION_LOSS_RATE_FIELD, field_names.EXPECTED_POPULATION_LOSS_RATE_LOW_INCOME_FIELD,
field_names.EXPECTED_POPULATION_LOSS_RATE_FIELD field_names.EXPECTED_POPULATION_LOSS_RATE_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX, + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.EXPECTED_POPULATION_LOSS_RATE_LOW_INCOME_FIELD, field_names.EXPECTED_POPULATION_LOSS_RATE_FIELD,
field_names.ENERGY_BURDEN_FIELD,
field_names.ENERGY_BURDEN_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.ENERGY_BURDEN_LOW_INCOME_FIELD, field_names.ENERGY_BURDEN_LOW_INCOME_FIELD,
field_names.PM25_FIELD, field_names.ENERGY_BURDEN_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.PM25_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.ENERGY_BURDEN_FIELD,
field_names.PM25_EXPOSURE_LOW_INCOME_FIELD, field_names.PM25_EXPOSURE_LOW_INCOME_FIELD,
field_names.DIESEL_FIELD, field_names.PM25_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.DIESEL_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.PM25_FIELD,
field_names.DIESEL_PARTICULATE_MATTER_LOW_INCOME_FIELD, field_names.DIESEL_PARTICULATE_MATTER_LOW_INCOME_FIELD,
field_names.TRAFFIC_FIELD, field_names.DIESEL_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.TRAFFIC_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.DIESEL_FIELD,
field_names.TRAFFIC_PROXIMITY_LOW_INCOME_FIELD, field_names.TRAFFIC_PROXIMITY_LOW_INCOME_FIELD,
field_names.HOUSING_BURDEN_FIELD, field_names.TRAFFIC_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.HOUSING_BURDEN_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.TRAFFIC_FIELD,
field_names.HOUSING_BURDEN_LOW_INCOME_FIELD, field_names.HOUSING_BURDEN_LOW_INCOME_FIELD,
field_names.LEAD_PAINT_FIELD, field_names.HOUSING_BURDEN_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LEAD_PAINT_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.HOUSING_BURDEN_FIELD,
field_names.LEAD_PAINT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD, field_names.LEAD_PAINT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD,
field_names.MEDIAN_HOUSE_VALUE_FIELD, field_names.LEAD_PAINT_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LEAD_PAINT_FIELD,
field_names.MEDIAN_HOUSE_VALUE_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.MEDIAN_HOUSE_VALUE_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.TSDF_FIELD, field_names.MEDIAN_HOUSE_VALUE_FIELD,
field_names.TSDF_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.HAZARDOUS_WASTE_LOW_INCOME_FIELD, field_names.HAZARDOUS_WASTE_LOW_INCOME_FIELD,
field_names.NPL_FIELD, field_names.TSDF_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.NPL_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.TSDF_FIELD,
field_names.SUPERFUND_LOW_INCOME_FIELD, field_names.SUPERFUND_LOW_INCOME_FIELD,
field_names.RMP_FIELD, field_names.NPL_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.RMP_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.NPL_FIELD,
field_names.RMP_LOW_INCOME_FIELD, field_names.RMP_LOW_INCOME_FIELD,
field_names.WASTEWATER_FIELD, field_names.RMP_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.WASTEWATER_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.RMP_FIELD,
field_names.WASTEWATER_DISCHARGE_LOW_INCOME_FIELD, field_names.WASTEWATER_DISCHARGE_LOW_INCOME_FIELD,
field_names.ASTHMA_FIELD, field_names.WASTEWATER_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.ASTHMA_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.WASTEWATER_FIELD,
field_names.ASTHMA_LOW_INCOME_FIELD, field_names.ASTHMA_LOW_INCOME_FIELD,
field_names.DIABETES_FIELD, field_names.ASTHMA_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.DIABETES_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.ASTHMA_FIELD,
field_names.DIABETES_LOW_INCOME_FIELD, field_names.DIABETES_LOW_INCOME_FIELD,
field_names.HEART_DISEASE_FIELD, field_names.DIABETES_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.HEART_DISEASE_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.DIABETES_FIELD,
field_names.HEART_DISEASE_LOW_INCOME_FIELD, field_names.HEART_DISEASE_LOW_INCOME_FIELD,
field_names.LIFE_EXPECTANCY_FIELD, field_names.HEART_DISEASE_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LOW_LIFE_EXPECTANCY_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.HEART_DISEASE_FIELD,
field_names.LOW_LIFE_EXPECTANCY_LOW_INCOME_FIELD, field_names.LOW_LIFE_EXPECTANCY_LOW_INCOME_FIELD,
field_names.MEDIAN_INCOME_AS_PERCENT_OF_AMI_FIELD, field_names.LOW_LIFE_EXPECTANCY_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LIFE_EXPECTANCY_FIELD,
field_names.LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD,
field_names.LOW_MEDIAN_INCOME_AS_PERCENT_OF_AMI_FIELD field_names.LOW_MEDIAN_INCOME_AS_PERCENT_OF_AMI_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX, + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD, field_names.MEDIAN_INCOME_AS_PERCENT_OF_AMI_FIELD,
field_names.LINGUISTIC_ISO_FIELD,
field_names.LINGUISTIC_ISOLATION_LOW_HS_EDUCATION_FIELD, field_names.LINGUISTIC_ISOLATION_LOW_HS_EDUCATION_FIELD,
field_names.UNEMPLOYMENT_FIELD,
field_names.UNEMPLOYMENT_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LINGUISTIC_ISO_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.LINGUISTIC_ISO_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.POVERTY_LESS_THAN_100_FPL_FIELD, field_names.LINGUISTIC_ISO_FIELD,
field_names.UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD,
field_names.UNEMPLOYMENT_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.UNEMPLOYMENT_FIELD,
field_names.POVERTY_LOW_HS_EDUCATION_FIELD,
field_names.POVERTY_LESS_THAN_200_FPL_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX,
field_names.POVERTY_LESS_THAN_100_FPL_FIELD field_names.POVERTY_LESS_THAN_100_FPL_FIELD
+ field_names.PERCENTILE_FIELD_SUFFIX, + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.POVERTY_LOW_HS_EDUCATION_FIELD, field_names.POVERTY_LESS_THAN_200_FPL_FIELD,
field_names.HIGH_SCHOOL_ED_FIELD, field_names.POVERTY_LESS_THAN_100_FPL_FIELD,
field_names.HIGH_SCHOOL_ED_FIELD + field_names.PERCENTILE_FIELD_SUFFIX, field_names.HIGH_SCHOOL_ED_FIELD + field_names.PERCENTILE_FIELD_SUFFIX,
field_names.LOW_HS_EDUCATION_FIELD, field_names.HIGH_SCHOOL_ED_FIELD,
field_names.THRESHOLD_COUNT,
field_names.UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD,
field_names.COMBINED_UNEMPLOYMENT_2010, field_names.COMBINED_UNEMPLOYMENT_2010,
field_names.CENSUS_DECENNIAL_UNEMPLOYMENT_FIELD_2009,
field_names.COMBINED_POVERTY_LESS_THAN_100_FPL_FIELD_2010, field_names.COMBINED_POVERTY_LESS_THAN_100_FPL_FIELD_2010,
field_names.ISLAND_AREAS_UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD, field_names.ISLAND_AREAS_UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD,
field_names.ISLAND_AREAS_POVERTY_LOW_HS_EDUCATION_FIELD, field_names.ISLAND_AREAS_POVERTY_LOW_HS_EDUCATION_FIELD,
field_names.ISLAND_AREAS_LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD, field_names.ISLAND_AREAS_LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD,
field_names.ISLAND_AREAS_LOW_HS_EDUCATION_FIELD,
] ]

View file

@ -1,5 +1,7 @@
from pathlib import Path from pathlib import Path
import json import json
from numpy import float64
import numpy as np
import pandas as pd import pandas as pd
from data_pipeline.etl.base import ExtractTransformLoad from data_pipeline.etl.base import ExtractTransformLoad
@ -129,7 +131,7 @@ class PostScoreETL(ExtractTransformLoad):
new_df = initial_states_df.rename( new_df = initial_states_df.rename(
columns={ columns={
"fips": "State Code", "fips": "State Code",
"state_name": "State Name", "state_name": field_names.STATE_FIELD,
"state_abbreviation": "State Abbreviation", "state_abbreviation": "State Abbreviation",
} }
) )
@ -206,7 +208,9 @@ class PostScoreETL(ExtractTransformLoad):
tiles_score_column_titles = list(constants.TILES_SCORE_COLUMNS.keys()) tiles_score_column_titles = list(constants.TILES_SCORE_COLUMNS.keys())
# filter the columns on full score # filter the columns on full score
score_tiles = score_county_state_merged_df[tiles_score_column_titles] score_tiles = score_county_state_merged_df[
tiles_score_column_titles
].copy()
score_tiles[constants.TILES_SCORE_FLOAT_COLUMNS] = score_tiles[ score_tiles[constants.TILES_SCORE_FLOAT_COLUMNS] = score_tiles[
constants.TILES_SCORE_FLOAT_COLUMNS constants.TILES_SCORE_FLOAT_COLUMNS
@ -238,9 +242,31 @@ class PostScoreETL(ExtractTransformLoad):
def _create_downloadable_data( def _create_downloadable_data(
self, score_county_state_merged_df: pd.DataFrame self, score_county_state_merged_df: pd.DataFrame
) -> pd.DataFrame: ) -> pd.DataFrame:
return score_county_state_merged_df[ df = score_county_state_merged_df[
constants.DOWNLOADABLE_SCORE_COLUMNS constants.DOWNLOADABLE_SCORE_COLUMNS
] ].copy(deep=True)
df_of_float_columns = df.select_dtypes(include=["float64"])
for column in df_of_float_columns.columns:
# TODO: create a schema for fields to make it more explicit and safe which
# fields are percentages.
if any(x in column for x in constants.PERCENT_PREFIXES_SUFFIXES):
# Convert percentages from fractions between 0 and 1 to an integer
# from 0 to 100.
df_100 = df[column] * 100
df_int = np.floor(
pd.to_numeric(df_100, errors="coerce")
).astype("Int64")
df[column] = df_int
else:
# Round all other floats.
df[column] = floor_series(
series=df[column].astype(float64),
number_of_decimals=constants.TILES_ROUND_NUM_DECIMALS,
)
return df
def transform(self) -> None: def transform(self) -> None:
logger.info("Transforming data sources for Score + County CSVs") logger.info("Transforming data sources for Score + County CSVs")
@ -297,7 +323,7 @@ class PostScoreETL(ExtractTransformLoad):
# Rename score column # Rename score column
downloadable_df_copy = downloadable_df.rename( downloadable_df_copy = downloadable_df.rename(
columns={ columns={
field_names.SCORE_L_COMMUNITIES: "Community of focus (v0.1)" field_names.SCORE_L_COMMUNITIES: "Identified as disadvantaged (v0.1)"
}, },
inplace=False, inplace=False,
) )

View file

@ -87,7 +87,7 @@ def states_transformed_expected():
return pd.DataFrame.from_dict( return pd.DataFrame.from_dict(
data={ data={
"State Code": pd.Series(["01", "02", "04"], dtype="string"), "State Code": pd.Series(["01", "02", "04"], dtype="string"),
"State Name": pd.Series( "State/Territory": pd.Series(
["Alabama", "Alaska", "Arizona"], dtype="object" ["Alabama", "Alaska", "Arizona"], dtype="object"
), ),
"State Abbreviation": pd.Series(["AL", "AK", "AZ"], dtype="string"), "State Abbreviation": pd.Series(["AL", "AK", "AZ"], dtype="string"),

File diff suppressed because one or more lines are too long

View file

@ -2,6 +2,7 @@ import pandas as pd
from data_pipeline.etl.base import ExtractTransformLoad from data_pipeline.etl.base import ExtractTransformLoad
from data_pipeline.utils import get_module_logger, download_file_from_url from data_pipeline.utils import get_module_logger, download_file_from_url
from data_pipeline.score import field_names
logger = get_module_logger(__name__) logger = get_module_logger(__name__)
@ -49,6 +50,20 @@ class CDCPlacesETL(ExtractTransformLoad):
values=self.CDC_VALUE_FIELD_NAME, values=self.CDC_VALUE_FIELD_NAME,
) )
# rename columns to be used in score
rename_fields = {
"Current asthma among adults aged >=18 years": field_names.ASTHMA_FIELD,
"Coronary heart disease among adults aged >=18 years": field_names.HEART_DISEASE_FIELD,
"Cancer (excluding skin cancer) among adults aged >=18 years": field_names.CANCER_FIELD,
"Diagnosed diabetes among adults aged >=18 years": field_names.DIABETES_FIELD,
"Physical health not good for >=14 days among adults aged >=18 years": field_names.PHYS_HEALTH_NOT_GOOD_FIELD,
}
self.df.rename(
columns=rename_fields,
inplace=True,
errors="raise",
)
# Make the index (the census tract ID) a column, not the index. # Make the index (the census tract ID) a column, not the index.
self.df.reset_index(inplace=True) self.df.reset_index(inplace=True)

View file

@ -5,6 +5,7 @@ from data_pipeline.etl.sources.census_acs.etl_utils import (
retrieve_census_acs_data, retrieve_census_acs_data,
) )
from data_pipeline.utils import get_module_logger from data_pipeline.utils import get_module_logger
from data_pipeline.score import field_names
logger = get_module_logger(__name__) logger = get_module_logger(__name__)
@ -22,7 +23,7 @@ class CensusACSETL(ExtractTransformLoad):
self.TOTAL_UNEMPLOYED_FIELD, self.TOTAL_UNEMPLOYED_FIELD,
self.TOTAL_IN_LABOR_FORCE, self.TOTAL_IN_LABOR_FORCE,
] ]
self.UNEMPLOYED_FIELD_NAME = "Unemployed civilians (percent)" self.UNEMPLOYED_FIELD_NAME = "Unemployment (percent)"
self.LINGUISTIC_ISOLATION_FIELD_NAME = "Linguistic isolation (percent)" self.LINGUISTIC_ISOLATION_FIELD_NAME = "Linguistic isolation (percent)"
self.LINGUISTIC_ISOLATION_TOTAL_FIELD_NAME = ( self.LINGUISTIC_ISOLATION_TOTAL_FIELD_NAME = (
@ -353,18 +354,29 @@ class CensusACSETL(ExtractTransformLoad):
+ df[self.COLLEGE_ATTENDANCE_FEMALE_ENROLLED_PRIVATE] + df[self.COLLEGE_ATTENDANCE_FEMALE_ENROLLED_PRIVATE]
) / df[self.COLLEGE_ATTENDANCE_TOTAL_POPULATION_ASKED] ) / df[self.COLLEGE_ATTENDANCE_TOTAL_POPULATION_ASKED]
# strip columns
df = df[self.COLUMNS_TO_KEEP]
# Save results to self. # Save results to self.
self.df = df self.df = df
# rename columns to be used in score
rename_fields = {
"Percent of individuals < 200% Federal Poverty Line": field_names.POVERTY_LESS_THAN_200_FPL_FIELD,
}
self.df.rename(
columns=rename_fields,
inplace=True,
errors="raise",
)
def load(self) -> None: def load(self) -> None:
logger.info("Saving Census ACS Data") logger.info("Saving Census ACS Data")
# mkdir census # mkdir census
self.OUTPUT_PATH.mkdir(parents=True, exist_ok=True) self.OUTPUT_PATH.mkdir(parents=True, exist_ok=True)
self.df[self.COLUMNS_TO_KEEP].to_csv( self.df.to_csv(path_or_buf=self.OUTPUT_PATH / "usa.csv", index=False)
path_or_buf=self.OUTPUT_PATH / "usa.csv", index=False
)
def validate(self) -> None: def validate(self) -> None:
logger.info("Validating Census ACS Data") logger.info("Validating Census ACS Data")

View file

@ -5,6 +5,7 @@ from data_pipeline.etl.sources.census_acs.etl_utils import (
retrieve_census_acs_data, retrieve_census_acs_data,
) )
from data_pipeline.utils import get_module_logger from data_pipeline.utils import get_module_logger
from data_pipeline.score import field_names
logger = get_module_logger(__name__) logger = get_module_logger(__name__)
@ -73,7 +74,7 @@ class CensusACS2010ETL(ExtractTransformLoad):
self.EMPLOYMENT_COLLEGE_IN_LABOR_FORCE, self.EMPLOYMENT_COLLEGE_IN_LABOR_FORCE,
] ]
self.UNEMPLOYED_FIELD_NAME = "Unemployed civilians (percent)" self.UNEMPLOYED_FIELD_NAME = "Unemployment (percent)"
self.POVERTY_FIELDS = [ self.POVERTY_FIELDS = [
"C17002_001E", # Estimate!!Total, "C17002_001E", # Estimate!!Total,
@ -149,15 +150,6 @@ class CensusACS2010ETL(ExtractTransformLoad):
+ df["C17002_007E"] + df["C17002_007E"]
) / df["C17002_001E"] ) / df["C17002_001E"]
# Save results to self.
self.df = df
def load(self) -> None:
logger.info("Saving Census ACS Data")
# mkdir census
self.OUTPUT_PATH.mkdir(parents=True, exist_ok=True)
columns_to_include = [ columns_to_include = [
self.GEOID_TRACT_FIELD_NAME, self.GEOID_TRACT_FIELD_NAME,
self.UNEMPLOYED_FIELD_NAME, self.UNEMPLOYED_FIELD_NAME,
@ -166,7 +158,7 @@ class CensusACS2010ETL(ExtractTransformLoad):
self.POVERTY_LESS_THAN_200_PERCENT_FPL_FIELD_NAME, self.POVERTY_LESS_THAN_200_PERCENT_FPL_FIELD_NAME,
] ]
output_df = self.df[columns_to_include] output_df = df[columns_to_include]
# Add the year to the end of every column, so when it's all joined in the # Add the year to the end of every column, so when it's all joined in the
# score df, it's obvious which year this data is from. # score df, it's obvious which year this data is from.
@ -178,7 +170,26 @@ class CensusACS2010ETL(ExtractTransformLoad):
} }
) )
output_df.to_csv(path_or_buf=self.OUTPUT_PATH / "usa.csv", index=False) # rename columns to be used in score
rename_fields = {
"Percent of individuals < 100% Federal Poverty Line in 2010": field_names.CENSUS_POVERTY_LESS_THAN_100_FPL_FIELD_2010,
}
output_df.rename(
columns=rename_fields,
inplace=True,
errors="raise",
)
# Save results to self.
self.df = output_df
def load(self) -> None:
logger.info("Saving Census ACS Data")
# mkdir census
self.OUTPUT_PATH.mkdir(parents=True, exist_ok=True)
self.df.to_csv(path_or_buf=self.OUTPUT_PATH / "usa.csv", index=False)
def validate(self) -> None: def validate(self) -> None:
logger.info("Validating Census ACS Data") logger.info("Validating Census ACS Data")

View file

@ -6,6 +6,7 @@ import pandas as pd
from data_pipeline.etl.base import ExtractTransformLoad from data_pipeline.etl.base import ExtractTransformLoad
from data_pipeline.utils import get_module_logger from data_pipeline.utils import get_module_logger
from data_pipeline.score import field_names
pd.options.mode.chained_assignment = "raise" pd.options.mode.chained_assignment = "raise"
@ -141,7 +142,9 @@ class CensusDecennialETL(ExtractTransformLoad):
"PBG036014" # Total!!Female!!In labor force!!Civilian!!Unemployed "PBG036014" # Total!!Female!!In labor force!!Civilian!!Unemployed
) )
self.UNEMPLOYMENT_FIELD_NAME = "Unemployed civilians (percent) in 2009" self.UNEMPLOYMENT_FIELD_NAME = (
field_names.CENSUS_DECENNIAL_UNEMPLOYMENT_FIELD_2009
)
var_list = [ var_list = [
self.MEDIAN_INCOME_FIELD, self.MEDIAN_INCOME_FIELD,

View file

@ -6,7 +6,7 @@ TOP_25_PERCENTILE_SUFFIX = " (top 25th percentile)"
# Geographic field names # Geographic field names
GEOID_TRACT_FIELD = "GEOID10_TRACT" GEOID_TRACT_FIELD = "GEOID10_TRACT"
STATE_FIELD = "State Name" STATE_FIELD = "State/Territory"
COUNTY_FIELD = "County Name" COUNTY_FIELD = "County Name"
# Score file field names # Score file field names
@ -45,7 +45,7 @@ MEDIAN_HOUSE_VALUE_PERCENTILE = 90
# Poverty / Income # Poverty / Income
POVERTY_FIELD = "Poverty (Less than 200% of federal poverty line)" POVERTY_FIELD = "Poverty (Less than 200% of federal poverty line)"
POVERTY_LESS_THAN_200_FPL_FIELD = ( POVERTY_LESS_THAN_200_FPL_FIELD = (
"Percent of individuals < 200% Federal Poverty Line" "Percent of individuals below 200% Federal Poverty Line"
) )
POVERTY_LESS_THAN_150_FPL_FIELD = ( POVERTY_LESS_THAN_150_FPL_FIELD = (
"Percent of individuals < 150% Federal Poverty Line" "Percent of individuals < 150% Federal Poverty Line"
@ -83,15 +83,15 @@ EXPECTED_POPULATION_LOSS_RATE_FIELD = (
) )
# Environment # Environment
DIESEL_FIELD = "Diesel particulate matter" DIESEL_FIELD = "Diesel particulate matter exposure"
PM25_FIELD = "Particulate matter (PM2.5)" PM25_FIELD = "PM2.5 in the air"
OZONE_FIELD = "Ozone" OZONE_FIELD = "Ozone"
TRAFFIC_FIELD = "Traffic proximity and volume" TRAFFIC_FIELD = "Traffic proximity and volume"
LEAD_PAINT_FIELD = "Percent pre-1960s housing (lead paint indicator)" LEAD_PAINT_FIELD = "Percent pre-1960s housing (lead paint indicator)"
WASTEWATER_FIELD = "Wastewater discharge" WASTEWATER_FIELD = "Wastewater discharge"
AGGREGATION_POLLUTION_FIELD = "Pollution Burden" AGGREGATION_POLLUTION_FIELD = "Pollution Burden"
RMP_FIELD = "Proximity to Risk Management Plan (RMP) facilities" RMP_FIELD = "Proximity to Risk Management Plan (RMP) facilities"
TSDF_FIELD = "Proximity to TSDF sites" TSDF_FIELD = "Proximity to hazardous waste sites"
NPL_FIELD = "Proximity to NPL sites" NPL_FIELD = "Proximity to NPL sites"
AIR_TOXICS_CANCER_RISK_FIELD = "Air toxics cancer risk" AIR_TOXICS_CANCER_RISK_FIELD = "Air toxics cancer risk"
RESPIRATORY_HAZARD_FIELD = "Respiratory hazard index" RESPIRATORY_HAZARD_FIELD = "Respiratory hazard index"
@ -106,22 +106,26 @@ HT_INDEX_FIELD = (
ENERGY_BURDEN_FIELD = "Energy burden" ENERGY_BURDEN_FIELD = "Energy burden"
# Health # Health
DIABETES_FIELD = "Diagnosed diabetes among adults aged >=18 years" DIABETES_FIELD = (
ASTHMA_FIELD = "Current asthma among adults aged >=18 years" "Diagnosed diabetes among adults aged greater than or equal to 18 years"
HEART_DISEASE_FIELD = "Coronary heart disease among adults aged >=18 years" )
CANCER_FIELD = "Cancer (excluding skin cancer) among adults aged >=18 years" ASTHMA_FIELD = (
"Current asthma among adults aged greater than or equal to 18 years"
)
HEART_DISEASE_FIELD = (
"Coronary heart disease among adults aged greater than or equal to 18 years"
)
CANCER_FIELD = "Cancer (excluding skin cancer) among adults aged greater than or equal to 18 years"
HEALTH_INSURANCE_FIELD = ( HEALTH_INSURANCE_FIELD = (
"Current lack of health insurance among adults aged 18-64 years" "Current lack of health insurance among adults aged 18-64 years"
) )
PHYS_HEALTH_NOT_GOOD_FIELD = ( PHYS_HEALTH_NOT_GOOD_FIELD = "Physical health not good for greater than or equal to 14 days among adults aged greater than or equal to 18 years"
"Physical health not good for >=14 days among adults aged >=18 years"
)
LIFE_EXPECTANCY_FIELD = "Life expectancy (years)" LIFE_EXPECTANCY_FIELD = "Life expectancy (years)"
LOW_LIFE_EXPECTANCY_FIELD = "Low life expectancy" LOW_LIFE_EXPECTANCY_FIELD = "Low life expectancy"
# Other Demographics # Other Demographics
TOTAL_POP_FIELD = "Total population" TOTAL_POP_FIELD = "Total population"
UNEMPLOYMENT_FIELD = "Unemployed civilians (percent)" UNEMPLOYMENT_FIELD = "Unemployment (percent)"
LINGUISTIC_ISO_FIELD = "Linguistic isolation (percent)" LINGUISTIC_ISO_FIELD = "Linguistic isolation (percent)"
HOUSEHOLDS_LINGUISTIC_ISO_FIELD = ( HOUSEHOLDS_LINGUISTIC_ISO_FIELD = (
"Percent of households in linguistic isolation" "Percent of households in linguistic isolation"
@ -139,25 +143,25 @@ CENSUS_DECENNIAL_POVERTY_LESS_THAN_100_FPL_FIELD_2009 = (
"Percentage households below 100% of federal poverty line in 2009" "Percentage households below 100% of federal poverty line in 2009"
) )
CENSUS_DECENNIAL_HIGH_SCHOOL_ED_FIELD_2009 = "Percent individuals age 25 or over with less than high school degree in 2009" CENSUS_DECENNIAL_HIGH_SCHOOL_ED_FIELD_2009 = "Percent individuals age 25 or over with less than high school degree in 2009"
CENSUS_DECENNIAL_UNEMPLOYMENT_FIELD_2009 = ( CENSUS_DECENNIAL_UNEMPLOYMENT_FIELD_2009 = "Unemployment (percent) in 2009"
"Unemployed civilians (percent) in 2009"
)
CENSUS_DECENNIAL_TOTAL_POPULATION_FIELD_2009 = "Total population in 2009" CENSUS_DECENNIAL_TOTAL_POPULATION_FIELD_2009 = "Total population in 2009"
CENSUS_DECENNIAL_AREA_MEDIAN_INCOME_PERCENT_FIELD_2009 = ( CENSUS_DECENNIAL_AREA_MEDIAN_INCOME_PERCENT_FIELD_2009 = (
"Median household income as a percent of territory median income in 2009" "Median household income as a percent of territory median income in 2009"
) )
LOW_CENSUS_DECENNIAL_AREA_MEDIAN_INCOME_PERCENT_FIELD_2009 = "Low median household income as a percent of territory median income in 2009" LOW_CENSUS_DECENNIAL_AREA_MEDIAN_INCOME_PERCENT_FIELD_2009 = "Low median household income as a percent of territory median income in 2009"
# Fields from 2010 ACS (loaded for comparison with the territories) # Fields from 2010 ACS (loaded for comparison with the territories)
CENSUS_UNEMPLOYMENT_FIELD_2010 = "Unemployed civilians (percent) in 2010" CENSUS_UNEMPLOYMENT_FIELD_2010 = "Unemployment (percent) in 2010"
CENSUS_POVERTY_LESS_THAN_100_FPL_FIELD_2010 = ( CENSUS_POVERTY_LESS_THAN_100_FPL_FIELD_2010 = (
"Percent of individuals < 100% Federal Poverty Line in 2010" "Percent of individuals less than 100% Federal Poverty Line in 2010"
) )
# Combined fields that merge island areas and states data # Combined fields that merge island areas and states data
COMBINED_CENSUS_TOTAL_POPULATION_2010 = ( COMBINED_CENSUS_TOTAL_POPULATION_2010 = (
"Total population in 2009 (island areas) and 2019 (states and PR)" "Total population in 2009 (island areas) and 2019 (states and PR)"
) )
COMBINED_UNEMPLOYMENT_2010 = "Unemployed civilians (percent) in 2009 (island areas) and 2010 (states and PR)" COMBINED_UNEMPLOYMENT_2010 = (
"Unemployment (percent) in 2009 (island areas) and 2010 (states and PR)"
)
COMBINED_POVERTY_LESS_THAN_100_FPL_FIELD_2010 = ( COMBINED_POVERTY_LESS_THAN_100_FPL_FIELD_2010 = (
"Percentage households below 100% of federal poverty line in 2009 (island areas) " "Percentage households below 100% of federal poverty line in 2009 (island areas) "
"and 2010 (states and PR)" "and 2010 (states and PR)"
@ -259,66 +263,77 @@ TRANSPORTATION_COSTS = "Transportation Costs"
##### #####
# Names for individual factors being exceeded # Names for individual factors being exceeded
# Climate Change # Climate Change
EXPECTED_POPULATION_LOSS_RATE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for expected population loss rate and is low income" EXPECTED_POPULATION_LOSS_RATE_LOW_INCOME_FIELD = (
EXPECTED_AGRICULTURE_LOSS_RATE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for expected agriculture loss rate and is low income" f"Greater than or equal to the {PERCENTILE}th percentile"
EXPECTED_BUILDING_LOSS_RATE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for expected building loss rate and is low income" f" for expected population loss rate and is low income?"
)
EXPECTED_AGRICULTURE_LOSS_RATE_LOW_INCOME_FIELD = (
f"Greater than or equal to the {PERCENTILE}th percentile"
f" for expected agriculture loss rate and is low income?"
)
EXPECTED_BUILDING_LOSS_RATE_LOW_INCOME_FIELD = (
f"Greater than or equal to the {PERCENTILE}th percentile"
f" for expected building loss rate and is low income?"
)
# Clean energy and efficiency # Clean energy and efficiency
PM25_EXPOSURE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for PM2.5 exposure and is low income" PM25_EXPOSURE_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for PM2.5 exposure and is low income?"
ENERGY_BURDEN_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for energy burden and is low income" ENERGY_BURDEN_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for energy burden and is low income?"
# Clean transportation # Clean transportation
DIESEL_PARTICULATE_MATTER_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for diesel particulate matter and is low income" DIESEL_PARTICULATE_MATTER_LOW_INCOME_FIELD = (
TRAFFIC_PROXIMITY_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for traffic proximity and is low income" f"Greater than or equal to the {PERCENTILE}th percentile for "
"diesel particulate matter and is low income?"
)
TRAFFIC_PROXIMITY_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for traffic proximity and is low income?"
# Affordable and Sustainable Housing # Affordable and Sustainable Housing
LEAD_PAINT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD = ( LEAD_PAINT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile for lead paint and" f"Greater than or equal to the {PERCENTILE}th percentile for lead paint and"
f" the median house value is less than {MEDIAN_HOUSE_VALUE_PERCENTILE}th " f" the median house value is less than {MEDIAN_HOUSE_VALUE_PERCENTILE}th "
f"percentile and is low income" f"percentile and is low income?"
) )
HOUSING_BURDEN_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for housing burden and is low income" HOUSING_BURDEN_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for housing burden and is low income?"
# Remediation and Reduction of Legacy Pollution # Remediation and Reduction of Legacy Pollution
RMP_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for proximity to RMP sites and is low income" RMP_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for proximity to RMP sites and is low income?"
SUPERFUND_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for proximity to superfund sites and is low income" SUPERFUND_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for proximity to superfund sites and is low income?"
HAZARDOUS_WASTE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for proximity to hazardous waste facilities and is low income" HAZARDOUS_WASTE_LOW_INCOME_FIELD = (
f"Greater than or equal to the {PERCENTILE}th percentile"
f" for proximity to hazardous waste facilities and is low income?"
)
# Critical Clean Water and Waste Infrastructure # Critical Clean Water and Waste Infrastructure
WASTEWATER_DISCHARGE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for wastewater discharge and is low income" WASTEWATER_DISCHARGE_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for wastewater discharge and is low income?"
# Health Burdens # Health Burdens
DIABETES_LOW_INCOME_FIELD = ( DIABETES_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for diabetes and is low income?"
f"At or above the {PERCENTILE}th percentile for diabetes and is low income" ASTHMA_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for asthma and is low income?"
) HEART_DISEASE_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for heart disease and is low income?"
ASTHMA_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile for asthma and is low income"
)
HEART_DISEASE_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for heart disease and is low income"
LOW_LIFE_EXPECTANCY_LOW_INCOME_FIELD = ( LOW_LIFE_EXPECTANCY_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile " f"Greater than or equal to the {PERCENTILE}th percentile "
f"for low life expectancy and is low income" f"for low life expectancy and is low income?"
) )
# Workforce # Workforce
UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD = ( UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for unemployment" f"Greater than or equal to the {PERCENTILE}th percentile for unemployment"
" and has low HS education" " and has low HS education"
) )
LINGUISTIC_ISOLATION_LOW_HS_EDUCATION_FIELD = ( LINGUISTIC_ISOLATION_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for households in linguistic isolation" f"Greater than or equal to the {PERCENTILE}th percentile for households in linguistic isolation"
" and has low HS education" " and has low HS education"
) )
POVERTY_LOW_HS_EDUCATION_FIELD = ( POVERTY_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for households at or below 100% federal poverty level" f"Greater than or equal to the {PERCENTILE}th percentile for households at or below 100% federal poverty level"
" and has low HS education" " and has low HS education"
) )
LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD = ( LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for low median household income as a " f"Greater than or equal to the {PERCENTILE}th percentile for low median household income as a "
f"percent of area median income and has low HS education" f"percent of area median income and has low HS education"
) )
@ -327,17 +342,17 @@ LOW_HS_EDUCATION_FIELD = "Low high school education"
# Workforce for island areas # Workforce for island areas
ISLAND_AREAS_SUFFIX = " in 2009 (island areas)" ISLAND_AREAS_SUFFIX = " in 2009 (island areas)"
ISLAND_AREAS_UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD = ( ISLAND_AREAS_UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for unemployment" f"Greater than or equal to the {PERCENTILE}th percentile for unemployment"
f" and has low HS education{ISLAND_AREAS_SUFFIX}" f" and has low HS education{ISLAND_AREAS_SUFFIX}"
) )
ISLAND_AREAS_POVERTY_LOW_HS_EDUCATION_FIELD = ( ISLAND_AREAS_POVERTY_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for households at or below 100% federal poverty level" f"Greater than or equal to the {PERCENTILE}th percentile for households at or below 100% federal poverty level"
f" and has low HS education{ISLAND_AREAS_SUFFIX}" f" and has low HS education{ISLAND_AREAS_SUFFIX}"
) )
ISLAND_AREAS_LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD = ( ISLAND_AREAS_LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for low median household income as a " f"Greater than or equal to the {PERCENTILE}th percentile for low median household income as a "
f"percent of area median income" f"percent of area median income"
f" and has low HS education{ISLAND_AREAS_SUFFIX}" f" and has low HS education{ISLAND_AREAS_SUFFIX}"
) )
@ -348,27 +363,27 @@ ISLAND_AREAS_LOW_HS_EDUCATION_FIELD = (
# Not currently used in a factor # Not currently used in a factor
EXTREME_HEAT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD = ( EXTREME_HEAT_MEDIAN_HOUSE_VALUE_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile for summer days above 90F and " f"Greater than or equal to the {PERCENTILE}th percentile for summer days above 90F and "
f"the median house value is less than {MEDIAN_HOUSE_VALUE_PERCENTILE}th " f"the median house value is less than {MEDIAN_HOUSE_VALUE_PERCENTILE}th "
f"percentile and is low income" f"percentile and is low income?"
) )
IMPENETRABLE_SURFACES_LOW_INCOME_FIELD = ( IMPENETRABLE_SURFACES_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile for impenetrable surfaces and is low " f"Greater than or equal to the {PERCENTILE}th percentile for impenetrable surfaces and is low "
f"income" f"income"
) )
AIR_TOXICS_CANCER_RISK_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for air toxics cancer risk and is low income" AIR_TOXICS_CANCER_RISK_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for air toxics cancer risk and is low income?"
RESPIRATORY_HAZARD_LOW_INCOME_FIELD = f"At or above the {PERCENTILE}th percentile for respiratory hazard index and is low income" RESPIRATORY_HAZARD_LOW_INCOME_FIELD = f"Greater than or equal to the {PERCENTILE}th percentile for respiratory hazard index and is low income?"
HEALTHY_FOOD_LOW_INCOME_FIELD = ( HEALTHY_FOOD_LOW_INCOME_FIELD = (
f"At or above the {PERCENTILE}th percentile for low " f"Greater than or equal to the {PERCENTILE}th percentile for low "
f"access to healthy food and is low income" f"access to healthy food and is low income?"
) )
LOW_READING_LOW_HS_EDUCATION_FIELD = ( LOW_READING_LOW_HS_EDUCATION_FIELD = (
f"At or above the {PERCENTILE}th percentile for low 3rd grade reading proficiency" f"Greater than or equal to the {PERCENTILE}th percentile for low 3rd grade reading proficiency"
" and has low HS education" " and has low HS education"
) )
THRESHOLD_COUNT = "Total threshold criteria exceeded" THRESHOLD_COUNT = "Total threshold criteria exceeded"
FPL_200_SERIES = "Is low income" FPL_200_SERIES = "Is low income?"
# End of names for individual factors being exceeded # End of names for individual factors being exceeded
#### ####