Adding Multiple Markers To A Folium Map Using City Names From Pandas Dataframe
Im trying to visualize data using folium maps, and I have to plot all Finlands' city names to the map. I've tried to use pandas dataframe since all my data is in csv format. Here's
Solution 1:
You can use geopy to get coordinates and then use a loop to add markers to your map:
import folium
from geopy.geocoders import Nominatim
import pandas as pd
geolocator = Nominatim(user_agent="example")
l = {'REGION': ['Kajaani','Lappeenranta','Pudasjärvi'],
'CUSTOMERS':['7','4','64']}
l['COORDS'] = []
for k in l['REGION']:
loc = geolocator.geocode(k).raw
l['COORDS'].append((loc['lat'], loc['lon']))
df = pd.DataFrame(l)
map_zoo = folium.Map(location=[65,26], zoom_start=4)
for i,r in df.iterrows():
folium.Marker(location=r['COORDS'],
popup = r['REGION'],
tooltip='Click for more information!').add_to(map_zoo)
map_zoo
and you get:
Post a Comment for "Adding Multiple Markers To A Folium Map Using City Names From Pandas Dataframe"