Skip to content
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

Closed
lewis500 opened this issue Jul 3, 2018 · 3 comments
Closed

get data for all block groups in a state #56

lewis500 opened this issue Jul 3, 2018 · 3 comments

Comments

@lewis500
Copy link

lewis500 commented Jul 3, 2018

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?

@hamzaamjad
Copy link

hamzaamjad commented Jul 19, 2018

@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)

@wtadler
Copy link

wtadler commented Dec 18, 2018

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?

@fgregg
Copy link
Member

fgregg commented Dec 18, 2018

@hamzaamjad is right. If we were to provide this method, we'd just use a version of the code they suggested.

@fgregg fgregg closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants