forked from mdbartos/RIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
census_year_compat.py
29 lines (19 loc) · 1.03 KB
/
census_year_compat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
import pandas as pd
import geopandas as gpd
from geopandas import tools
census_old = '/home/kircheis/data/shp/census/census_tracts_all/census_tracts_1990.shp'
census_new = '/home/kircheis/data/shp/census/census_tracts_all/census_tracts_2014.shp'
df_90 = gpd.read_file(census_old)
df_14 = gpd.read_file(census_new)
df_14_c = df_14.copy()
df_14_c['geometry'] = df_14_c.centroid
j = tools.sjoin(df_90, df_14_c, op='contains')
#### FORMAT CENSUS TRACT NAMES
#### NONDECIMAL ENTRIES
j['TRACT_NAME'][~j['TRACT_NAME'].str.contains('\.')] = (j['TRACT_NAME'][~j['TRACT_NAME'].str.contains('\.')] + '00').str.pad(6, side='left', fillchar='0')
#### DECIMAL ENTRIES
j['TRACT_NAME'][j['TRACT_NAME'].str.contains('\.')] = j['TRACT_NAME'][j['TRACT_NAME'].str.contains('\.')].str.replace('.', '').str.pad(6, side='left', fillchar='0')
#### CREATE FIPS
j['GEOID_1990'] = j['ST'].astype(str).str.cat(j['CO'].astype(str)).str.cat(j['TRACT_NAME'])
j_cross = j.rename(columns={'GEOID':'GEOID_2014'})[['GEOID_1990', 'GEOID_2014']].sort('GEOID_1990')