this imports the needed programs to run the code (pandas)(for some reason folium has to be installed on its own using pip)
import folium
import pandas as pd
!pip install folium
Requirement already satisfied: folium in /opt/conda/envs/heatmap/lib/python3.9/site-packages (0.14.0) Requirement already satisfied: branca>=0.6.0 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from folium) (0.6.0) Requirement already satisfied: jinja2>=2.9 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from folium) (3.1.2) Requirement already satisfied: numpy in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from folium) (1.24.3) Requirement already satisfied: requests in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from folium) (2.31.0) Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from jinja2>=2.9->folium) (2.1.3) Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from requests->folium) (3.1.0) Requirement already satisfied: idna<4,>=2.5 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from requests->folium) (3.4) Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from requests->folium) (2.0.3) Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/heatmap/lib/python3.9/site-packages (from requests->folium) (2023.5.7)
this code first makessure the correct things are imported then loads a file (this can be enterchanged but for this it is cholera data) then it creates the map, it loads follium along with the latitude and longitude data then it adds a layer for a heatmap identifying the traits that are being shown (lat and lon should stay, but deaths_r is just what it is for cholera data, it is just talking about how it is a confirmed case) then it saves it as an html file that can be viewed. if you are doing different datasets, change the name so you can keep them seperate
import pandas as pd
import folium
from folium.plugins import HeatMap
# 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, lang='en')
# Define Gradient
# Add heatmap layer to the map
HeatMap(data=data[['Latitude', 'Longitude', 'deaths_r']].groupby(['Latitude', 'Longitude']).sum().reset_index().values.tolist(), radius=8, max_zoom=13, opacity=0.7).add_to(map)
# Save the map to an HTML file
map.save('choleraheatmapfinal.html')
This is a random data creator. If you need to test that the code is working this will create a dataset, and once it is created if you run the code above (with the right names) it should give you a randomized hotspot around tucson az.
import pandas as pd
df = pd.DataFrame(index=range(100))
import numpy as np
df['latitude'] = np.random.uniform(low=31, high=34, size=(100,))
df['longitude'] = np.random.uniform(low=-112, high=-110, size=(100,))
df['occurance'] = np.random.choice([1, 0], size=(100,))
df.to_csv('data.csv', index=False)