census
census copied to clipboard
How to get population by zip code?
I am trying to query the population by zip code, but I am not sure how to approach it with this library.
Have you tried the acs5.zipcode
method? The variable for total population is B01003_001E
, so you should be able to make calls like this (with zip code 60608):
>>> c.acs5.zipcode('B01003_001E', 60608)
[{'B01003_001E': 78877.0, 'zip code tabulation area': '60608'}]
@jeancochrane : I am looking to do the same thing, however for my application, I need ACS1, do you know if there is way to get this data for acs1 ? I don't see a zipcode method for acs1, so I am looking at alternatives.
@UGuntupalli I don't think zip code tabulation areas are an available geography for ACS1, see: https://www.census.gov/programs-surveys/geography/guidance/geo-areas/zctas.html#ti129385160 My understanding is that ACS1 doesn't have a large enough sample size to accurately reflect that level of geographic resolution, but I'm not an expert. Here's a comparison of different yearly estimates: https://www.census.gov/programs-surveys/acs/guidance/estimates.html
@jeancochrane , Thank you for pointing me to that resource. For the problem I am trying to solve, a reasonable estimate and an approximation of level of change is sufficient. I am not really bothered about the precision, so if there is a way to do it with ACS1 that would be great. Thank you for clarifying that zip code tabulation is not available. I opened a new issue to see if county level query can be run. (#91)
As an alternative, you might try https://github.com/datamade/census_area, which extends this library to let you query by arbitrary geographies (you could use a GeoJSON of the zip codes you care about). The precision of the estimate will probably be misleading but if you don't care so much about that it might work for you.
Hm, I seem to be getting an error now using c.acs5.zipcode
, when I run the above I get:
c.acs5.zipcode('B01003_001E', 60608)
CensusException: error: ambiguous geography "zip code tabulation area:60608". You must either specify a wildcard or full qualify it with state
Not sure what this means?
@VincentLa While I couldn't get it to work as it's meant to. I have been able to pull the needed data by passing zcta = '*' into the function. It will return a list of dictionaries (one for each zip code). Not ideal, but you can loop through it and pull the data for your zip code of interest
@UGuntupalli , were you able to figure out anyway to get ACS1 estimates?