How to use the censusdata.download function in CensusData

To help you get started, we’ve selected a few CensusData examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jtleider / censusdata / test / test_export.py View on Github external
def test_export(self):
		data = censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '*')]), ['B01001_001E'])
		try:
			csv = StringIO.StringIO()
		except NameError:
			csv = io.StringIO()
		censusdata.exportcsv(csv, data)
		self.maxDiff = None
		self.assertEqual(csv.getvalue(), textwrap.dedent("""\
		state,NAME,B01001_001E
		01,Alabama,4830620
		02,Alaska,733375
		04,Arizona,6641928
		05,Arkansas,2958208
		06,California,38421464
		08,Colorado,5278906
		09,Connecticut,3593222
		10,Delaware,926454
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs5_200914(self):
		medhhinc = {2009: 55222, 2010: 55735, 2011: 56576, 2012: 56853, 2013: 56797, 2014: 57166}
		for year in range(2009, 2014+1):
			assert_frame_equal(censusdata.download('acs5', year, censusdata.censusgeo([('state', '17')]), ['B19013_001E']),
				pd.DataFrame({'B19013_001E': medhhinc[year]}, [censusdata.censusgeo([('state', '17')], 'Illinois')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_sf1_2010(self):
		assert_frame_equal(censusdata.download('sf1', 2010, censusdata.censusgeo([('state', '17'), ('place', '14000')]), ['P001001']),
			pd.DataFrame({'P001001': 2695598}, [censusdata.censusgeo([('state', '17'), ('place', '14000')])]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs3_detail(self):
		medhhinc = {2012: 55231, 2013: 55799}
		for year in medhhinc:
			assert_frame_equal(censusdata.download('acs3', year, censusdata.censusgeo([('state', '17')]), ['B19013_001E']),
				pd.DataFrame({'B19013_001E': medhhinc[year]}, [censusdata.censusgeo([('state', '17')], 'Illinois')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs1_2018(self):
		assert_frame_equal(censusdata.download('acs1', 2018, censusdata.censusgeo([('state', '17')]), ['B19013_001E']),
			pd.DataFrame({'B19013_001E': 65030}, [censusdata.censusgeo([('state', '17')], 'Illinois')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs5_2015(self):
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '06'), ('place', '53000')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 408073, 'B01002_001E': 36.3, 'B19013_001E': 54618}, [censusdata.censusgeo([('state', '06'), ('place', '53000')], 'Oakland city, California')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '15'), ('county', '*')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': [191482, 984178, 85, 69691, 160863], 'B01002_001E': [41.1, 36.9, 51.9, 41.6, 40], 'B19013_001E': [52108, 74460, 66250, 65101, 66476]}, 
				[censusdata.censusgeo([('state', '15'), ('county', '001')], 'Hawaii County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '003')], 'Honolulu County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '005')], 'Kalawao County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '007')], 'Kauai County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '009')], 'Maui County, Hawaii')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 1293, 'B19013_001E': 49375}, [censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')], 'Block Group 2, Census Tract 3501, Cook County, Illinois')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 9534008, 'B19013_001E': 61828}, [censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')], 'Chicago-Naperville-Elgin, IL-IN-WI Metro Area')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '06')]), ['DP03_0021PE'], tabletype='profile'),
			pd.DataFrame({'DP03_0021PE': 5.2}, [censusdata.censusgeo([('state', '06')], 'California')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_gt50_vars(self):
		vars = ['DP05_{:04}PE'.format(i) for i in range(1, 84+1)]
		data = censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '06')]), vars, tabletype='profile')
		expected = pd.DataFrame({'DP05_0001PE': 38421464, 'DP05_0002PE': 49.7, 'DP05_0003PE': 50.3, 'DP05_0004PE': 6.5, 'DP05_0005PE': 6.6,
			'DP05_0006PE': 6.6, 'DP05_0007PE': 6.9, 'DP05_0008PE': 7.6, 'DP05_0009PE': 14.6, 'DP05_0010PE': 13.5, 'DP05_0011PE': 13.7,
			'DP05_0012PE': 6.2, 'DP05_0013PE': 5.3, 'DP05_0014PE': 7.0, 'DP05_0015PE': 3.8, 'DP05_0016PE': 1.7, 'DP05_0017PE': -888888888,
			'DP05_0018PE': 76.1, 'DP05_0019PE': 71.7, 'DP05_0020PE': 15.5, 'DP05_0021PE': 12.5, 'DP05_0022PE': 29247121, 'DP05_0023PE': 49.2,
			'DP05_0024PE': 50.8, 'DP05_0025PE': 4797320, 'DP05_0026PE': 44.0, 'DP05_0027PE': 56.0, 'DP05_0028PE': 38421464, 'DP05_0029PE': 95.5,
			'DP05_0030PE': 4.5, 'DP05_0031PE': 95.5, 'DP05_0032PE': 61.8, 'DP05_0033PE': 5.9, 'DP05_0034PE': 0.7, 'DP05_0035PE': 0.1, 'DP05_0036PE': 0.0,
			'DP05_0037PE': 0.0, 'DP05_0038PE': 0.0, 'DP05_0039PE': 13.7, 'DP05_0040PE': 1.7, 'DP05_0041PE': 3.6, 'DP05_0042PE': 3.2,
			'DP05_0043PE': 0.7, 'DP05_0044PE': 1.2, 'DP05_0045PE': 1.6, 'DP05_0046PE': 1.6, 'DP05_0047PE': 0.4, 'DP05_0048PE': 0.1, 'DP05_0049PE': 0.1,
			'DP05_0050PE': 0.1, 'DP05_0051PE': 0.2, 'DP05_0052PE': 12.9, 'DP05_0053PE': 4.5, 'DP05_0054PE': 0.6, 'DP05_0055PE': 0.7, 'DP05_0056PE': 1.3,
			'DP05_0057PE': 0.1, 'DP05_0058PE': 38421464, 'DP05_0059PE': 65.5, 'DP05_0060PE': 7.1, 'DP05_0061PE': 1.9, 'DP05_0062PE': 15.6,
			'DP05_0063PE': 0.8, 'DP05_0064PE': 14.1, 'DP05_0065PE': 38421464, 'DP05_0066PE': 38.4, 'DP05_0067PE': 31.9, 'DP05_0068PE': 0.5,
			'DP05_0069PE': 0.2, 'DP05_0070PE': 5.7, 'DP05_0071PE': 61.6, 'DP05_0072PE': 38.7, 'DP05_0073PE': 5.6, 'DP05_0074PE': 0.4,
			'DP05_0075PE': 13.5, 'DP05_0076PE': 0.4, 'DP05_0077PE': 0.2, 'DP05_0078PE': 2.8, 'DP05_0079PE': 0.1, 'DP05_0080PE': 2.7,
			'DP05_0081PE': -888888888, 'DP05_0082PE': 24280349, 'DP05_0083PE': 49.0, 'DP05_0084PE': 51.0},
			[censusdata.censusgeo([('state', '06')])])
		assert_frame_equal(data, expected)
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs5_2015(self):
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '06'), ('place', '53000')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 408073, 'B01002_001E': 36.3, 'B19013_001E': 54618}, [censusdata.censusgeo([('state', '06'), ('place', '53000')], 'Oakland city, California')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '15'), ('county', '*')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': [191482, 984178, 85, 69691, 160863], 'B01002_001E': [41.1, 36.9, 51.9, 41.6, 40], 'B19013_001E': [52108, 74460, 66250, 65101, 66476]}, 
				[censusdata.censusgeo([('state', '15'), ('county', '001')], 'Hawaii County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '003')], 'Honolulu County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '005')], 'Kalawao County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '007')], 'Kauai County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '009')], 'Maui County, Hawaii')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 1293, 'B19013_001E': 49375}, [censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')], 'Block Group 2, Census Tract 3501, Cook County, Illinois')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 9534008, 'B19013_001E': 61828}, [censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')], 'Chicago-Naperville-Elgin, IL-IN-WI Metro Area')]))
		assert_frame_equal(censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '06')]), ['DP03_0021PE'], tabletype='profile'),
			pd.DataFrame({'DP03_0021PE': 5.2}, [censusdata.censusgeo([('state', '06')], 'California')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acs5_2016(self):
		assert_frame_equal(censusdata.download('acs5', 2016, censusdata.censusgeo([('state', '06'), ('place', '53000')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 412040, 'B01002_001E': 36.2, 'B19013_001E': 57778}, [censusdata.censusgeo([('state', '06'), ('place', '53000')], 'Oakland city, California')]))
		assert_frame_equal(censusdata.download('acs5', 2016, censusdata.censusgeo([('state', '15'), ('county', '*')]), ['B01001_001E', 'B01002_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': [193680, 986999, 91, 70447, 162456], 'B01002_001E': [41.8, 37.4, 56.5, 42.0, 40.5], 'B19013_001E': [53936, 77161, 65625, 68224, 68777]}, 
				[censusdata.censusgeo([('state', '15'), ('county', '001')], 'Hawaii County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '003')], 'Honolulu County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '005')], 'Kalawao County, Hawaii'),
				censusdata.censusgeo([('state', '15'), ('county', '007')], 'Kauai County, Hawaii'), censusdata.censusgeo([('state', '15'), ('county', '009')], 'Maui County, Hawaii')]))
		assert_frame_equal(censusdata.download('acs5', 2016, censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 1374, 'B19013_001E': 44044}, [censusdata.censusgeo([('state', '17'), ('county', '031'), ('tract', '350100'), ('block group', '2')], 'Block Group 2, Census Tract 3501, Cook County, Illinois')]))
		assert_frame_equal(censusdata.download('acs5', 2016, censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')]), ['B01001_001E', 'B19013_001E']),
			pd.DataFrame({'B01001_001E': 9528396, 'B19013_001E': 63327}, [censusdata.censusgeo([('metropolitan statistical area/micropolitan statistical area', '16980')], 'Chicago-Naperville-Elgin, IL-IN-WI Metro Area')]))
		assert_frame_equal(censusdata.download('acs5', 2016, censusdata.censusgeo([('state', '06')]), ['DP03_0021PE'], tabletype='profile'),
			pd.DataFrame({'DP03_0021PE': 5.2}, [censusdata.censusgeo([('state', '06')], 'California')]))
github jtleider / censusdata / test / test_download.py View on Github external
def test_download_acsse(self):
		nocomputer = {2014: 731135, 2015: 658047, 2016: 522736, 2017: 464053}
		for year in range(2014, 2017+1):
			assert_frame_equal(censusdata.download('acsse', year, censusdata.censusgeo([('state', '17')]), ['K202801_006E']),
				pd.DataFrame({'K202801_006E': nocomputer[year]}, [censusdata.censusgeo([('state', '17')], 'Illinois')]))

CensusData

Download data from U.S. Census API

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages