3 ms·
import pandas as pd import geopandas as gpd census_df = pd.read_excel('census_data_yuge.xlsx').fillna(0) muni_df = pd.read_excel('muni_data_yuge.xlsx.').
by anigbrowl 4y ago
import pandas as pd
import geopandas as gpd
census_df = pd.read_excel('census_data_yuge.xlsx').fillna(0)
muni_df = pd.read_excel('muni_data_yuge.xlsx.').fillna(0)
# assumes same criteria & column names in both
census_df.drop(['address 1', 'address 2', 'zip'], inplace=True)
muni_df.drop(['address 1', 'address 2', 'zip'], inplace=True)
cities = gpd.DataFrame(muni_df.groupby(['city']).mean() - census_df.groupby(['city']).dropna().mean())
gpd.plot(column='num_residents', cmap='bwr')
A fun exercise. I stuck to the time but score it as a C- because I cheated with geopandas (which I've never used but seems to do a lot of this out of the box) and gave myself unrealistically clean imaginary data. I have parsed census data once and remember it being a lot of work to tidy up before I even tried to answer my question.
- anigbrowl 4y agomfw realizing the last line should be cities.plot... ToT