Heatmap On Folium With Pandas
I have following syntax which does not deliver what I am trying to do: df_bedarf = pd.read_csv('C:/Users/xxxxxx/Desktop/xxxxx/xxxxxx.csv', sep = ';') df_bedarf.head() df_locations
Solution 1:
The easiest way to change the color for each marker is to use the bin classification function on a numeric column and set the desired color name for that numeric value. If you want to increase the number of colors, increase the bins and labels.
import pandas as pd
import numpy as np
import io
data = '''
Suburb Sort t/a Latitude Longitude
0 Wien CC 2272 48.201900 16.370000
1 Graz LD 426 47.079675 15.420325
2 Feldbach LD 248 46.952187 15.888309
3 Zerlach RE 2041 46.944865 15.650902
4 Gnas SM 1488 46.874198 15.826138
'''
df_locations = pd.read_csv(io.StringIO(data), delim_whitespace=True)
colors = pd.cut(df_locations['t/a'], bins=4, labels=['hotpink', 'tomato', 'red', 'crimson'])
colors = colors.to_list()
df_locations
Suburb Sort t/a Latitude Longitude marker_color
0 Wien CC 227248.20190016.370000 crimson
1 Graz LD 42647.07967515.420325 hotpink
2 Feldbach LD 24846.95218715.888309 hotpink
3 Zerlach RE 204146.94486515.650902 crimson
4 Gnas SM 148846.87419815.826138 red
map_points = folium.Map(location = [47.57087, 13.43828], zoom_start = 7)
for idx, row in df_locations.iterrows():
folium.Circle(
location = [row['Latitude'], row['Longitude']],
popup=row["Suburb"] + ": " + row["Sort"],
radius = 10000,
# blur = 10000,
color=colors[idx],
fill_color=colors[idx],
# min_opacity=0.3,# max_zoom=1,
).add_to(map_points)
map_points
Post a Comment for "Heatmap On Folium With Pandas"