interface module¶
This module is how we connect the PUMAs and their ratios for a given ZIP code to the ACS dataset. It is called for each ZIP code to return the summary statistics or dataframe for that specific ZIP code.
- ziptool.interface.get_acs_data(file: Union[str, pathlib.Path, pandas.core.frame.DataFrame], state_fips_code: Union[int, str], pumas: List[str], variables: Optional[Dict[str, str]] = None)¶
Pulls ACS data from a given file and extracts the data pertraining to a particular ZIP code. Can either return the full raw data or summary statistics.
- Parameters
file – a path to a datafile OR a dataframe containing ACS datafile
variables –
To extract summary statistics, pass a dictionary of the form:
{ variable_of_interest_1: { "null": null_val, "type": type }, variable_of_interest_2: { "null": null_val, "type": type }... }
variable_of_interest: the variable name you wish to summarize null_val: the value, as a float or integer, of null values to filter out. type: “household” or “individual”, depending on the variable type
To return the raw data, pass None.
state_fips_code – an integer (or two-digit representation thereof) representing the state of interest’s FIPS codes
pumas – each PUMA of interest within the state and its ratio (returned by geo_conversion.tracts_to_puma)
- Returns
When variables of interest are passed, a pd.DataFrame containing the summary statistics.
- When variables of interest are NOT passed, a dictionary of the form::
{puma_1: [puma1_df, ratio1], puma_2: [puma2_df, ratio2]…}