In [1]:
import seaborn as sns
import metapack as mp
import pandas as pd
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display 

%matplotlib inline
sns.set_context('notebook')

In [2]:
pkg = mp.jupyter.open_package()
#pkg = mp.jupyter.open_source_package()
pkg


Out[2]:

San Diego PUMS

census.gov-pums-20165-1 Last Update: 2018-11-30T03:50:49

PUMS Housing and personal records for San Diego county.

Documentation Links

Contacts

Resources

References


In [3]:
from publicdata import  parse_app_url

url = parse_app_url('census://2015/5/CA/140/B17001')
tracts = url.geoframe()

In [4]:
parse_app_url('census://2015/5/CA/140/B17001').geo_url.shape_url


Out[4]:
<FtpUrl shape+ftp://ftp2.census.gov/geo/tiger/TIGER2015/TRACT/tl_2015_06_tract.zip>

In [5]:
tracts.plot()


Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x122c85f98>

In [6]:
# The puma files moved, so the publicdata package is wrong. 
url = parse_app_url('shape+ftp://ftp2.census.gov/geo/tiger/TIGER2018/PUMA/tl_2018_06_puma10.zip')
pumas = url.get_resource().geoframe()

In [7]:
pumas.plot()


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x122d4d5f8>

In [8]:
counties_pkg = mp.open_package('http://library.metatab.org/census.gov-counties-2017-2.csv')
counties = counties_pkg.resource('counties').geoframe()
sd = counties[counties.name == 'San Diego']

In [9]:
# The direct route crashes: Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 287.
sd_pumas = pumas[pumas.GEOID10.str.startswith('06073')]
sd_pumas.plot()


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x122949278>

In [ ]:


In [10]:
sd_pumas_tracts = gpd.sjoin(tracts, sd_pumas)
sd_pumas_tracts = sd_pumas_tracts[sd_pumas_tracts.countyfp == '073'].copy()
sd_pumas_tracts.plot(column='PUMACE10')


Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x122d16d68>

In [11]:
#sd_pumas_tracts.to_file('tracts.geojson','GeoJSON')
#sd_pumas.to_file('pumas.geojson','GeoJSON')

In [12]:
t = sd_pumas_tracts[['geoid', 'GEOID10']]
from geoid.census import CensusGeoid, State_puma5, Tract
t = pd.DataFrame({
    'puma_geoid': sd_pumas_tracts.GEOID10.apply(lambda v: State_puma5.parse(v).as_acs()),
    'tract_geoid': sd_pumas_tracts.geoid.apply(lambda v: Tract.parse(v).as_acs())
    } 
)

t = t.reset_index(drop=True)
t.to_csv('sandiego_puma_tract.csv')

In [13]:
url = parse_app_url('census://2016/5/CA/795/B03002')
pums_pop = url.dataframe()
pums_pop.titles.head().T


Out[13]:
GEOID 79500US0600101 79500US0600102 79500US0600103 79500US0600104 79500US0600105
STUSAB CA CA CA CA CA
COUNTY
NAME Alameda County (North)--Berkeley & Albany Citi... Alameda County (Northwest)--Oakland (Northwest... Alameda County (Northeast)--Oakland (East) & P... Alameda County (North Central)--Oakland City (... Alameda County (West)--San Leandro, Alameda & ...
B03002_001 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Total: 137963 166408 130663 133480 171116
B03002_001_m90 157 1728 1622 1880 644
B03002_002 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: 122233 134237 117735 68817 135345
B03002_002_m90 1070 2025 1489 1897 1449
B03002_003 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - White alone 75152 45646 69479 9814 54854
B03002_003_m90 1434 1299 1173 764 1441
B03002_004 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Black or African American alone 10459 39562 20848 39514 17454
B03002_004_m90 797 1570 1043 1484 1146
B03002_005 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - American Indian and Alaska Native alone 398 945 343 333 532
B03002_005_m90 104 206 110 124 156
B03002_006 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Asian alone 27765 38675 18135 13033 52578
B03002_006_m90 1061 1522 884 949 1368
B03002_007 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Native Hawaiian and Other Pacific Islander alone 512 940 401 940 1422
B03002_007_m90 206 309 149 377 439
B03002_008 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Some other race alone 564 657 507 269 684
B03002_008_m90 206 237 160 185 349
B03002_009 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Two or more races: 7383 7812 8022 4914 7821
B03002_009_m90 679 866 882 762 816
B03002_010 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Two or more races: - Two races including Some other race 347 467 186 50 393
B03002_010_m90 191 191 149 47 220
B03002_011 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Not Hispanic or Latino: - Two or more races: - Two races excluding Some other race, and three or more races 7036 7345 7836 4864 7428
B03002_011_m90 643 833 849 758 771
B03002_012 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: 15730 32171 12928 64663 35771
B03002_012_m90 1086 1652 867 1896 1396
B03002_013 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - White alone 7869 14177 5987 24520 19600
B03002_013_m90 690 1237 626 1891 1576
B03002_014 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Black or African American alone 289 1086 243 1187 447
B03002_014_m90 131 313 120 418 225
B03002_015 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - American Indian and Alaska Native alone 408 965 103 696 763
B03002_015_m90 163 415 116 298 365
B03002_016 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Asian alone 104 227 237 93 589
B03002_016_m90 61 95 194 56 273
B03002_017 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Native Hawaiian and Other Pacific Islander alone 0 0 43 51 171
B03002_017_m90 28 28 49 42 119
B03002_018 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Some other race alone 4573 12454 4233 35277 10555
B03002_018_m90 700 1406 629 2376 1468
B03002_019 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Two or more races: 2487 3262 2082 2839 3646
B03002_019_m90 420 477 348 683 565
B03002_020 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Two or more races: - Two races including Some other race 980 1402 939 1338 1788
B03002_020_m90 308 271 258 349 449
B03002_021 HISPANIC OR LATINO ORIGIN BY RACE for Total Population - Hispanic or Latino: - Two or more races: - Two races excluding Some other race, and three or more races 1507 1860 1143 1501 1858
B03002_021_m90 302 421 276 572 369

In [14]:
!pwd


/Users/eric/proj/virt-proj/data-project/sdrdl-data-projects/census.gov/census.gov-pums-20165/notebooks

In [ ]: