I'm at a loss about why this works just fine for all variables when pulling tract data, but only for some variables when pulling block group data. For example, median income works for all tracts in CA but returns None for all block groups (see out[0], B06011_001E below). This problem does not exist for total population.
from census import Census
from us import states
cvname = {'B01003_001E':'TotPop','B02001_001E':'RaceTot',
'B02001_002E':'WhiteTot','B02001_003E':'BlackTot',
'B03001_003E':'HispTot','B06011_001E':'MedInc'}
nametup = tuple([v for v in cvname.keys()])
# Easily get API key here: https://api.census.gov/data/key_signup.html
c = Census("YOUR_API_KEY")
cty = 1
out = c.acs5.get(nametup,{'for':'block group:*','in':'state:{} county:{:03} tract:*'.format(
states.CA.fips,cty)})
out2 = c.acs5.get(nametup,{'for':'tract:*','in':'state:{} county:{:03}'.format(
states.CA.fips,cty)})
> In [1]: out[0]
> Out[1]:
> {u'B01003_001E': 1755.0,
> u'B02001_001E': 1755.0,
> u'B02001_002E': 764.0,
> u'B02001_003E': 0.0,
> u'B03001_003E': None,
> u'B06011_001E': None,
> u'block group': '3',
> u'county': '001',
> u'state': '06',
> u'tract': '444100'}
>
> In [2]: out2[0]
> Out[2]:
> {u'B01003_001E': 6570.0,
> u'B02001_001E': 6570.0,
> u'B02001_002E': 855.0,
> u'B02001_003E': 111.0,
> u'B03001_003E': 570.0,
> u'B06011_001E': 44375.0,
> u'county': '001',
> u'state': '06',
> u'tract': '441501'}