Created
May 25, 2019 11:35
-
-
Save do-me/1dc5c7595743f1f9468d360089d0f619 to your computer and use it in GitHub Desktop.
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
# multi choropleth | |
import pandas as pd | |
import os | |
pd.set_option('precision', 10) | |
os.chdir("C:/Users/Dome/Desktop/nu/Wahl- und Strukturdaten/Tabellen/") | |
ma = pd.read_csv("MASTERENG.csv",float_precision='round_trip') | |
import folium | |
import webbrowser | |
state_geo="C:/Users/Dome/Desktop/nu/Wahl- und Strukturdaten/Wahlkreise.geojson" | |
# a loop might be implemented here, but be useless, as the file size | |
# would grow too much | |
# the final file size is around 80 Mb | |
m = folium.Map(location=[51, 10], zoom_start=5) # focus on germany | |
# create 4 choropleth maps | |
m.choropleth(geo_data=state_geo, name='Index Delta 2017-2013', data=df, columns=["District No.","deltaindex"], | |
key_on='feature.properties.WKR_NR', fill_color='PuOr', fill_opacity=0.8, | |
line_opacity=0.3, legend_name='Index Delta 2017-2013', highlight=True) | |
m.choropleth(geo_data=state_geo, name='Voting Index 2017', data=df, columns=["District No.","selfindex17"], | |
key_on='feature.properties.WKR_NR', fill_color='PuOr', fill_opacity=0.8, | |
line_opacity=0.3, legend_name='Voting Index 2017', highlight=True) | |
m.choropleth(geo_data=state_geo, name='Voting Index 2013', data=df, columns=["District No.","selfindex13"], | |
key_on='feature.properties.WKR_NR', fill_color='PuOr', fill_opacity=0.8, | |
line_opacity=0.3, legend_name='Voting Index 2013', highlight=True) | |
m.choropleth(geo_data=state_geo, name='AfD Votes 2017', data=df, columns=["District No.","afd17"], | |
key_on='feature.properties.WKR_NR', fill_color='YlOrBr', fill_opacity=0.8, | |
line_opacity=0.3, legend_name='AfD Votes 2017 in %', highlight=True) | |
folium.LayerControl().add_to(m) # useful for multiple layers | |
# Save to html in your directory | |
m.save("C:/Users/Dome/Desktop/nu/Karten/t1.html") | |
# open html file in your standard browser | |
webbrowser.open("C:/Users/Dome/Desktop/nu/Karten/t1.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment