This page describes how to add markers to your folium map. It is done using the folium.Marker function. Note that you can custom the popup window of each marker with any html code!
# import libraries import folium import pandas as pd # Make a data frame with dots to show on the map data = pd.DataFrame({ 'lat':[-58, 2, 145, 30.32, -4.03, -73.57, 36.82, -38.5], 'lon':[-34, 49, -38, 59.93, 5.33, 45.52, -1.29, -12.97], 'name':['Buenos Aires', 'Paris', 'melbourne', 'St Petersbourg', 'Abidjan', 'Montreal', 'Nairobi', 'Salvador'] }) data # Make an empty map m = folium.Map(location=[20, 0], tiles="Mapbox Bright", zoom_start=2) # I can add marker one by one on the map for i in range(0,len(data)): folium.Marker([data.iloc[i]['lon'], data.iloc[i]['lat']], popup=data.iloc[i]['name']).add_to(m) # Save it as html m.save('312_markers_on_folium_map1.html')
pd is not recognized if we don’t import pandas in the code.
So before importing folium we write this code
‘import pandas as pd’
then code runs perfectly
Indeed this was a mistake! Thanks for your feedback, code has been updated.
Hi,
Thanks for this awesome code.
I trying to plot from a dataframe with around 160 (longitude and latitude) and m will not display
Is there a limitation to the length of data that can be plotted ?
Thanks
Hi Nadeem,
I don’t think there is any limitation.
You could try your code with only ~10 data points to check that it works first.
Good luck!
Yan