Search code examples
pythonlistfor-loopfolium

For loop to replace word in string with name in list


I need a for loop to replace "name" in html string below with a name from name_lst. The expected output should be the plotted map with a name at each coordinate from the lists below.

lat_lst = [48.6064556,52.9399159,46.510712,51.253775,53.9332706,53.7266683,53.7608608,53.1355,46.5653163,52.9399159,70.2997711,64.8255441,64.2823274]
lng_lst = [-56.3330408,-106.4508639,-63.4168136,-85.3232139,-116.5765035,-127.6476206,-98.8138763,-57.6604,-66.4619164,-73.5491361,-83.1075769,-124.8457334,-135.00000]
name_lst = ['Nova Scotia','Saskatchewan','Prince Edward Island','Ontario','Alberta','British Columbia','Manitoba','Newfoundland and Labrador','New Brunswick','Quebec','Nunavut','Northwest Terrritories','Yukon']


for lat, lng, name in zip(lat_lst, lng_lst, name_lst):
html.replace("name",name_lst,1)
folium.map.Marker(
    location=[lat,lng],
    icon=DivIcon(
    icon_size=(150,36),
    icon_anchor=(0,0),
    html='<div style="font-size: 10pt">name</div>',
    )).add_to(m)

Getting error : TypeError: zip argument #3 must support iteration

If anyone could help me create a Tooltip for this, it would be awesome to see the name when hovering over the coordinates.


Solution

  • Update, managed to solve this problem by concatenation:

    lat_lst = [48.6064556,52.9399159,46.510712,51.253775,53.9332706,53.7266683,53.7608608,53.1355,46.5653163,52.9399159,70.2997711,64.8255441,64.2823274]
    lng_lst = [-56.3330408,-106.4508639,-63.4168136,-85.3232139,-116.5765035,-127.6476206,-98.8138763,-57.6604,-66.4619164,-73.5491361,-83.1075769,-124.8457334,-135.00000]
    name_lst = ['Nova Scotia','Saskatchewan','Prince Edward Island','Ontario','Alberta','British Columbia','Manitoba','Newfoundland and Labrador','New Brunswick','Quebec','Nunavut','Northwest Terrritories','Yukon']
    
    for lat, lng, name in zip(lat_lst, lng_lst, name_lst):
        folium.map.Marker(
        location=[lat,lng],
        icon=DivIcon(
        icon_size=(150,36),
        icon_anchor=(0,0),
        html='<div style="font-size: 10pt">'+name+'</div>',
    )).add_to(temp_map)
    temp_map
    

    Produces the correct name on the map: enter image description here