In [26]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('snowdatanew.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='OpenStreetMap')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=13, min_opacity=0.99, opacity=0.3, radius=15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 100px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>COVID-19 Origin</b><br>
Data retrieved from Michael Woroby's initial COVID-19 origin study<br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCholeraHeatmap.html')
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('snowdatanew.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='OpenStreetMap')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=13, min_opacity=0.99, opacity=0.3, radius=15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
COVID-19 Origin
Data retrieved from Michael Woroby's initial COVID-19 origin study
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCholeraHeatmap.html')
Data retrieved from Michael Woroby's initial COVID-19 origin study
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) File /opt/conda/envs/heatmap/lib/python3.9/site-packages/pandas/core/indexes/base.py:3652, in Index.get_loc(self, key) 3651 try: -> 3652 return self._engine.get_loc(casted_key) 3653 except KeyError as err: File /opt/conda/envs/heatmap/lib/python3.9/site-packages/pandas/_libs/index.pyx:147, in pandas._libs.index.IndexEngine.get_loc() File /opt/conda/envs/heatmap/lib/python3.9/site-packages/pandas/_libs/index.pyx:176, in pandas._libs.index.IndexEngine.get_loc() File pandas/_libs/hashtable_class_helper.pxi:7080, in pandas._libs.hashtable.PyObjectHashTable.get_item() File pandas/_libs/hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item() KeyError: 'latitude' The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) Cell In[26], line 10 7 data = pd.read_csv('snowdatanew.csv') 9 # Create a base map ---> 10 map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='OpenStreetMap') 12 # Add heatmap layer to the map 13 heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=13, min_opacity=0.99, opacity=0.3, radius=15) File /opt/conda/envs/heatmap/lib/python3.9/site-packages/pandas/core/frame.py:3761, in DataFrame.__getitem__(self, key) 3759 if self.columns.nlevels > 1: 3760 return self._getitem_multilevel(key) -> 3761 indexer = self.columns.get_loc(key) 3762 if is_integer(indexer): 3763 indexer = [indexer] File /opt/conda/envs/heatmap/lib/python3.9/site-packages/pandas/core/indexes/base.py:3654, in Index.get_loc(self, key) 3652 return self._engine.get_loc(casted_key) 3653 except KeyError as err: -> 3654 raise KeyError(key) from err 3655 except TypeError: 3656 # If we have a listlike key, _check_indexing_error will raise 3657 # InvalidIndexError. Otherwise we fall through and re-raise 3658 # the TypeError. 3659 self._check_indexing_error(key) KeyError: 'latitude'
In [28]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('snowdatanew.csv')
# Calculate the center coordinates
center_lat = 51.51316190483689
center_lon = -0.1370434028316683
# Create a base map with specific zoom and view
map = folium.Map(location=[center_lat, center_lon], zoom_start=15, tiles= 'OpenStreetMap')
# Create a base map
#map = folium.Map(location=[data['Latitude'].mean(), data['Longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['Latitude', 'Longitude', 'deaths_r']].groupby(['Latitude', 'Longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=50, min_opacity=0.99, opacity=0.3, radius=12)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['deaths_r'].min(), vmax=data['deaths_r'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 125px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>1854 Cholera Origin</b><br>
Data retrieved from Univerity of Chicago's Center for Spacial Data Science <br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('CholeraFinal.html')
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('snowdatanew.csv')
# Calculate the center coordinates
center_lat = 51.51316190483689
center_lon = -0.1370434028316683
# Create a base map with specific zoom and view
map = folium.Map(location=[center_lat, center_lon], zoom_start=15, tiles= 'OpenStreetMap')
# Create a base map
#map = folium.Map(location=[data['Latitude'].mean(), data['Longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['Latitude', 'Longitude', 'deaths_r']].groupby(['Latitude', 'Longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=50, min_opacity=0.99, opacity=0.3, radius=12)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['deaths_r'].min(), vmax=data['deaths_r'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
1854 Cholera Origin
Data retrieved from Univerity of Chicago's Center for Spacial Data Science
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('CholeraFinal.html')
Data retrieved from Univerity of Chicago's Center for Spacial Data Science
In [ ]:
Copied!
Last update:
2023-08-08