New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get data for all block groups in a state #56
Comments
@lewis500 There may be better ways to pull data for all blockgroups, but why not generate a list of counties first, and then iterate over that? See below as an example from census import Census
from us import states
import pandas as pd
c = Census("YOUR_KEY_HERE")
stateCodes = states.mapping("fips", "name")
countyCodes = []
for state in stateCodes:
temp = c.acs5.state_county("NAME", state, Census.ALL)
countyCodes.append({state : temp})
censusBlockGroups = []
for state in countyCodes:
for key, value in state.items():
for element in value:
censusBlockGroups.append(c.acs5.state_county_blockgroup("NAME", element["state"], element["county"], Census.ALL))
censusBlockGroups = [item for sublist in censusBlockGroups for item in sublist]
censusBlockGroups = pd.DataFrame(censusBlockGroups) |
I'm also interested in this—is there a way to do this without having to iterate over all counties? Also, is there any way to use this package to get data from individual blocks, rather than block groups? |
@hamzaamjad is right. If we were to provide this method, we'd just use a version of the code they suggested. |
Hi I want to be able to look at all the block groups in a state.
So for example to look at all the block groups in a county I would go:
c.acs5.state_county_blockgroup('NAME', states.AK.fips, '170', Census.ALL)
But if I try to reply the "county" argument with Census.ALL I get an error.
c.acs5.state_county_blockgroup('NAME', states.AK.fips,Census.ALL, Census.ALL)
Is there a way to do this?
The text was updated successfully, but these errors were encountered: