census icon indicating copy to clipboard operation
census copied to clipboard

Support census blocks?

Open Kirkman opened this issue 2 years ago • 3 comments

Thanks for the fantastic library. I noticed that there is support for obtaining block-group-level data, but not block-level. Is there any chance you can add support for blocks?

Kirkman avatar Feb 04 '22 19:02 Kirkman

IIRC, while the Census collects data at the block level, they only report at the block-group level and above.

WrightWillT avatar Feb 22 '23 18:02 WrightWillT

No, their API does provide block-level data for some datasets. For example, the 2020 Redistricting Data Summary File (PL 94-171) has block-level data.

You can test this for yourself by adding the following function to core.py:

@supported_years()
def state_county_block(self, fields, state_fips, county_fips, block, tract=None, **kwargs):
	geo = {
		'for': 'block:{}'.format(block),
		'in': 'state:{} county:{}'.format(state_fips, county_fips),
	}
	if tract:
		geo['in'] += ' tract:{}'.format(tract)
	return self.get(fields, geo=geo, **kwargs)

And then running a query like this:

data = c.pl.state_county_block(
	('NAME', 'P1_001N'), # table
	'29', # state
	'189', # county
	Census.ALL, # blockgroup
	year='2020'
)

Kirkman avatar Feb 22 '23 20:02 Kirkman

@Kirkman mind if I copy this and do a pull request?

PhilipMathieu avatar Mar 25 '23 14:03 PhilipMathieu