Last Updated on March 27, 2023 by mishou

I. What shall we learn?

Let’s learn how to create a world map with markeres with Folium like this:


We can see the scripts here:

Map with markers with Python and Folium

We can learn the differences among Altir, Plotly, and Folium here:

Interactive Choropleth Maps in Python Using Altair, Plotly, and Folium


The scripts in the first link convert all the data to objects and might get an error when you create a map. You should remove “,dtype=str” from the scripts in this case, though there must some reason for the conversions.

# import libraries
# import libraries
import pandas as pd
import folium
# create a data frame
data = pd.DataFrame({
   'lon': [-58, 2, 145, 30.32, 30.31, -4.03, -73.57, 36.82, -38.5],
   'lat': [-34, 49, -38, 59.93, 50.27, 5.33, 45.52, -1.29, -12.97],
   'name': ['Buenos Aires', 'Paris', 'Melbourne', 'St_Petersbourg', 'Kyiv', 'Abidjan', 'Montreal', 'Nairobi', 'Salvador'],
   'population': [2891082, 2165423, 5159211, 5351935, 2962180, 3677115, 1762949, 4397073, 2886698],

You can put variables on Pop-up texts and I have inserted the population of each city and the URL of the page of each city on Wikipedia.

# create an empty map
n = folium.Map(location=[20,0], tiles="OpenStreetMap", zoom_start=2)
# add markers
for i in range(0,len(data)):
        <h1> {data.iloc[i]['name']}</h1>
        <p>You can use any html here! Let's do a list:</p>
            <li>Population {data.iloc[i]['population']}</li>
            <li>Item 2</li>
        <p>And that's a <a href="">link</a></p> # should be changed
    iframe = folium.IFrame(html=html, width=200, height=200)
    popup = folium.Popup(iframe, max_width=2650)
        location=[data.iloc[i]['lat'], data.iloc[i]['lon']],
                <circle cx="50" cy="50" r="40" fill="#69b3a2" opacity=".4"/>
                <rect x="35", y="35" width="30" height="30", fill="red", opacity=".3" 

# Show the map again

You can see the scripts on Google Colaboratory here:

By mishou

Leave a Reply

Your email address will not be published. Required fields are marked *