Closed mgraber closed 3 years ago
import pandas as pd
import os
from census import Census
c = Census(os.environ['API_KEY'])
nyc_counties = ['005', '081', '085', '047', '061']
variables = [
'B19013_001E', 'B25002_001E',
'B25002_002E', 'B25070_001E',
'B25070_007E', 'B25070_008E',
'B25070_009E', 'B25070_010E',
'B25091_001E', 'B25091_002E',
'B25091_008E', 'B25091_009E',
'B25091_010E', 'B25091_011E',
'B25091_019E', 'B25091_020E',
'B25091_021E', 'B25091_022E',
'B19001_002E', 'B19001_003E',
'B19001_004E', 'B19001_005E',
'B19001_006E', 'B19001_007E',
'B19001_008E', 'B19001_009E',
'B19001_010E', 'B19001_011E',
'B19001_012E', 'B19001_013E',
'B19001_014E', 'B19001_015E',
'B19001_016E', 'B19001_017E'
]
MHHI_bins = {'B19001_002E': [0, 9999],
'B19001_003E': [10000, 14999],
'B19001_004E': [15000, 19999],
'B19001_005E': [20000, 24999],
'B19001_006E': [25000, 29999],
'B19001_007E': [30000, 34999],
'B19001_008E': [35000, 39999],
'B19001_009E': [40000, 44999],
'B19001_010E': [45000, 49999],
'B19001_011E': [50000, 59999],
'B19001_012E': [60000, 74999],
'B19001_013E': [75000, 99999],
'B19001_014E': [100000, 124999],
'B19001_015E': [125000, 149999],
'B19001_016E': [150000, 199999],
'B19001_017E': [200000, 9999999]}
dfs = []
for county in nyc_counties:
dfs.append(pd.DataFrame(
c.acs5.get(('NAME', ','.join(variables)),
{'for': 'block group:*','in' : 'state:36 county:081'},year=2018)
))
df = pd.concat(dfs)
df_MHHI = df[['B19001_002E', 'B19001_003E',
'B19001_004E', 'B19001_005E',
'B19001_006E', 'B19001_007E',
'B19001_008E', 'B19001_009E',
'B19001_010E', 'B19001_011E',
'B19001_012E', 'B19001_013E',
'B19001_014E', 'B19001_015E',
'B19001_016E', 'B19001_017E']]
df['cost_burden_value'] = df.B25091_019E + df.B25091_020E + df.B25091_021E \
+ df.B25091_022E + df.B25091_008E + df.B25091_009E \
+ df.B25091_010E + df.B25091_011E
df['cost_burden'] = df.cost_burden_value / df.B25091_001E
df['mhhi'] = df_MHHI.apply(lambda row: get_median(MHHI_bins, row), axis=1)
df['mortg_value'] = df.B25091_002E
df['ownerocc'] = df.B25002_002E / df.B25002_001E
df['ownerocc_value'] = df.B25091_001E
df['permortg'] = df.B25091_002E / df.B25091_001E
df['rent_burden_value'] = df.B25070_007E + df.B25070_008E + \
df.B25070_009E + df.B25070_010E
df['rent_burden'] = df.rent_burden_value / df.B25070_001E
11
ACS-derived variables
Methodology
Example API call to extract census block group level ACS data by county https://api.census.gov/data/2018/acs/acs5?get=B00001_001E&for=block%20group:*&in=state:01%20county:025
Input tables
Note: to calculate estimates on Rent/Owner Cost Burdened Housholds, add 30.0 to 34.9 percent, 35.0 to 39.9 percent, 40.0 to 49.9 percent, 50.0 pecent or more & calculate associated MOE
Geography of census blocks, as related to the two floodplains
Decennial-derived variables
Methodology
Example API call to extract census block level decennial data by county https://api.census.gov/data/2010/dec/sf1?get=P001001,NAME&for=block:*&in=state:01%20county:009