-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractivemap.py
More file actions
38 lines (33 loc) · 1.41 KB
/
interactivemap.py
File metadata and controls
38 lines (33 loc) · 1.41 KB
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
30
31
32
33
34
35
36
37
38
"Interactive Map of Deaths in United States (1999-2016)"
"@Autors: Kristin Aoki and Sina "
#--------------------------------------------------------------------------------------
import csv
import operator
import pandas as pd
import os
import folium
from folium import Choropleth, Map, Marker, LayerControl
from folium import IFrame
state_geo = os.path.join('data', 'us_states.json')
state_deaths = os.path.join('data','death.csv')
state_data = pd.read_csv(state_deaths)
marker_data = os.path.join('data', 'StateLonandLat1999-2016.csv')#need to make this a more universal statement because each each has own file
marker_coord = pd.read_csv(marker_data)
#establishes the center of map based on longitude and latitude
m = Map(location=[50.246366, -110], zoom_start=4)
class AverageMap:
#sets the color scheme, data used for legend, and legend labels
Choropleth(geo_data=state_geo,name='choropleth',data=state_data,
columns=['State', 'Death Rate'],
key_on='feature.id',
fill_color='BuPu',
fill_opacity=0.7,
line_opacity=0.5,
legend_name='Average Death Rate (1999-2016)'
).add_to(m)
for i in range(0,len(marker_coord)):
popup = folium.Popup(marker_coord.iloc[i]['state'],max_width=350)
Marker([marker_coord.iloc[i]['lon'],marker_coord.iloc[i]['lat']], popup=popup).add_to(m)
LayerControl().add_to(m)
if __name__ == "__main__":
m.save('AverageMap.html')