Skip to content
Snippets Groups Projects
Commit f4d78549 authored by wiltand1's avatar wiltand1 Committed by Colbry, Dirk
Browse files

Add files via upload

Adding notebook to census branch.
parent 486b16c3
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:78ccb82d tags:
# Censusdata tutorial
Useful link:
https://jtleider.github.io/censusdata/example1.html
https://jtleider.github.io/censusdata/api.html
https://jtleider.github.io/censusdata/example3.html
%% Cell type:markdown id:dc5fcca9 tags:
### Install censusdata library
%% Cell type:code id:54211a3c tags:
``` python
pip install censusdata
```
%% Output
Collecting censusdata
Downloading CensusData-1.15.tar.gz (26.6 MB)
 |████████████████████████████████| 26.6 MB 5.5 MB/s eta 0:00:01
[?25hRequirement already satisfied: pandas in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from censusdata) (1.3.4)
Requirement already satisfied: requests in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from censusdata) (2.27.1)
Requirement already satisfied: python-dateutil>=2.7.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (2021.3)
Requirement already satisfied: numpy>=1.17.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (1.20.3)
Requirement already satisfied: six>=1.5 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas->censusdata) (1.16.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (1.26.7)
Requirement already satisfied: idna<4,>=2.5 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (3.2)
Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (2021.10.8)
Building wheels for collected packages: censusdata
Building wheel for censusdata (setup.py) ... [?25ldone
[?25h Created wheel for censusdata: filename=CensusData-1.15-py3-none-any.whl size=28205534 sha256=67f5d3391f90bc0e7dba31614e537f4acd16155c871442aeb1cd9a322a4f3f14
Stored in directory: /Users/liruohong/Library/Caches/pip/wheels/f7/28/2d/3308dceb3ca282b1479585690170f0a00821d9b36cbf835159
Successfully built censusdata
Installing collected packages: censusdata
Successfully installed censusdata-1.15
Note: you may need to restart the kernel to use updated packages.
%% Cell type:markdown id:e7581483 tags:
### Import libararys
Import censusdata libararys
Import pandas libarary for data processing
%% Cell type:code id:dbda6a76 tags:
``` python
import pandas as pd
import censusdata
```
%% Cell type:markdown id:569bec68 tags:
### Method of censusdata library
censusdata.search(src, year,field, criterion,tabletype): search for given text patterns
censusdata.censustable():identified table of interest
censusdata.printtable():show all variables included in the identified table of interest
censusdata.geographies():
censusdata.download():download the selected data
%% Cell type:code id:5b7a5a3e tags:
``` python
censusdata.search('acs5', 2015, 'label', 'unemploy')[80:90]
```
%% Output
[('B23024_023E',
'POVERTY STATUS IN THE PAST 12 MONTHS BY DISABILITY STATUS BY EMPLOYMENT STATUS FOR THE POPULATION 20 TO 64 YEARS',
'Estimate!!Total!!Income in the past 12 months at or above poverty level!!With a disability!!In labor force!!Civilian!!Unemployed'),
('B23024_030E',
'POVERTY STATUS IN THE PAST 12 MONTHS BY DISABILITY STATUS BY EMPLOYMENT STATUS FOR THE POPULATION 20 TO 64 YEARS',
'Estimate!!Total!!Income in the past 12 months at or above poverty level!!No disability!!In labor force!!Civilian!!Unemployed'),
('B23025_005E',
'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER',
'Estimate!!Total!!In labor force!!Civilian labor force!!Unemployed'),
('B27011_014E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed'),
('B27011_015E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years'),
('B27011_016E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage'),
('B27011_017E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage!!With private health insurance'),
('B27011_018E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage!!With public coverage'),
('B27011_019E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!No health insurance coverage'),
('B27011_020E',
'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',
'Estimate!!Total!!In labor force!!Unemployed!!65 years and over')]
%% Cell type:code id:40cbfb96 tags:
``` python
censusdata.printtable(censusdata.censustable('acs5', 2015, 'B23025'))
```
%% Output
Variable | Table | Label | Type
-------------------------------------------------------------------------------------------------------------------
B23025_001E | EMPLOYMENT STATUS FOR THE POPU | !! Estimate Total | int
B23025_002E | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total In labor force | int
B23025_003E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Civilian labor fo | int
B23025_004E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int
B23025_005E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int
B23025_006E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Armed Forces | int
B23025_007E | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total Not in labor force | int
-------------------------------------------------------------------------------------------------------------------
%% Cell type:code id:2bf2bc44 tags:
``` python
censusdata.printtable(censusdata.censustable('acs5', 2015, 'B23025'))
```
%% Output
Variable | Table | Label | Type
-------------------------------------------------------------------------------------------------------------------
B23025_001E | EMPLOYMENT STATUS FOR THE POPU | !! Estimate Total | int
B23025_002E | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total In labor force | int
B23025_003E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Civilian labor fo | int
B23025_004E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int
B23025_005E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int
B23025_006E | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Armed Forces | int
B23025_007E | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total Not in labor force | int
-------------------------------------------------------------------------------------------------------------------
%% Cell type:markdown id:1a3e0003 tags:
### Class for representing Census geographies: censusdata.censusgeo(geo,name)
censusdata.censusgeo.hierarchy():Geography hierarchy for the geographic level of this object
censusdata.censusgeo.params():Geographic parameters of this object.
censusdata.censusgeo.request():Generate geographic parameters for Census API request.
censusdata.censusgeo.sumlevel():Summary level code for the geographic level of this object.
%% Cell type:code id:4572b9e7 tags:
``` python
geo = censusdata.censusgeo([('state', '17'), ('county', '031')])
print(geo)
print(geo.params())
print(geo.request())
print(geo.sumlevel())
```
%% Output
Summary level: 050, state:17> county:031
(('state', '17'), ('county', '031'))
{'for': 'county:031', 'in': 'state:17'}
050
%% Cell type:code id:e8d800b3 tags:
``` python
```
%% Cell type:code id:ec541cba tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment