Created
July 27, 2020 11:44
-
-
Save KerryHalupka/81ec04519a3ace065bc8fb123ece74c9 to your computer and use it in GitHub Desktop.
Merge dataframes and display using geopandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_merged = pd.merge(lga_gdf[['LGA_CODE20', 'geometry', 'LGA_NAME20']], emp_df[['LGA_2016', 'percent_unemployed']], left_on='LGA_CODE20', right_on='LGA_2016', how='left') | |
df_merged = df_merged.dropna(subset=['percent_unemployed', 'LGA_CODE20', 'geometry']) | |
# OPTIONAL: Display using geopandas | |
fig, ax = plt.subplots(1,1, figsize=(20,20)) | |
divider = make_axes_locatable(ax) | |
tmp = df_merged.copy() | |
tmp['percent_unemployed'] = tmp['percent_unemployed']*100 #To display percentages | |
cax = divider.append_axes("right", size="3%", pad=-1) #resize the colorbar | |
tmp.plot(column='percent_unemployed', ax=ax,cax=cax, legend=True, | |
legend_kwds={'label': "Unemployment rate"}) | |
tmp.geometry.boundary.plot(color='#BABABA', ax=ax, linewidth=0.3) #Add some borders to the geometries | |
ax.axis('off') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment