This time we'll join a table of US Census data to a Census Tract shapefile and create a choropleth map of the results.
>>> import pandas as pd
>>> import geopandas as gpd
>>> import matplotlib.pyplot as plt
>>> import os
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import os
>>> os.chdir('../')
>>> os.getcwd()
os.chdir('../../')
os.getcwd()
>>> BoulderTracts = gpd.read_file('workshopdata/Boulder_Co_Tracts.shp')
>>> BoulderTracts
BoulderTracts = gpd.read_file('Data/Boulder_Co_Tracts.shp')
BoulderTracts
>>> BoulderMHHI = pd.read_csv('workshopdata/Boulder_Co_MHHI.csv')
>>> BoulderMHHI
BoulderMHHI = pd.read_csv('Data/Boulder_Co_MHHI.csv')
BoulderMHHI
Take a close look at GEOID10:
>>> print(BoulderMHHI.GEOID10)
>>> print(BoulderTracts.GEOID10)
print(BoulderMHHI.GEOID10)
print(BoulderTracts.GEOID10)
>>> BoulderMHHI = pd.read_csv('workshopdata/Boulder_Co_MHHI.csv', dtype={'GEOID10':str})
>>> BoulderMHHI
BoulderMHHI = pd.read_csv('Data/Boulder_Co_MHHI.csv', dtype={"GEOID10":str})
BoulderMHHI
BoulderMHHI_Tracts = BoulderTracts.merge(BoulderMHHI, on = 'GEOID10')
>>> BoulderMHHI_Tracts
BoulderMHHI_Tracts
BoulderMHHI_Tracts.plot('MHHI2014')
>>> BoulderMHHI_Tracts.plot('MHHI2014', cmap='RdYlGn', figsize=(10,10))
BoulderMHHI_Tracts.plot('MHHI2014', cmap='RdYlGn', figsize=(10,10))
BoulderMHHI_Tracts.to_file('Data/BoulderMHHI_Tracts.geojson', driver='GeoJSON')