1 回答
TA贡献1847条经验 获得超7个赞
我的补充数据是新加坡政府气象站温度数据。我已经对其进行了操作以适合您的示例
更改
location
和zoom
参数,因为新加坡在不同的地方并且小得多;-)您的核心问题是将字符串替换为
html
变量。我更喜欢 f-strings,所以将其更改为这个并且它有效。
import folium
import pandas as pd
df = pd.DataFrame({'latitude': [1.3764, 1.256, 1.3337, 1.3135, 1.3399, 1.2799],
'longitude': [103.8492, 103.679, 103.7768, 103.9625, 103.8878, 103.8703],
'value': [32.3, 31.7, 32.2, 29.9, 32.1, 32.5],
'tooltip': ['32.3 Ang Mo Kio Avenue 5 August 09, 2020 at 01:00PM',
'31.7 Banyan Road August 09, 2020 at 01:00PM',
'32.2 Clementi Road August 09, 2020 at 01:00PM',
'29.9 East Coast Parkway August 09, 2020 at 01:00PM',
'32.1 Kim Chuan Road August 09, 2020 at 01:00PM',
'32.5 Marina Gardens Drive August 09, 2020 at 01:00PM']})
data = df.copy().rename({'latitude':"LAT",'longitude':"LON",'value':"ELEV",'tooltip':"NAME"}, axis=1)
latitudes = list(data["LAT"])
longitudes = list(data["LON"])
elevations = list(data["ELEV"])
names = list(data["NAME"])
def myhtml(name, elev):
return f"""
Volcano name:<br>
<a href="https://www.google.com/search?q=%%22%{name}%%22" target="_blank">{name}</a><br>
Height: {elev} m
"""
map = folium.Map(location=[1.34, 103.82], zoom_start=12, tiles="Stamen Terrain")
fg = folium.FeatureGroup(name="My Map")
for lat, lon, elev, name in zip(latitudes, longitudes, elevations, names):
iframe = folium.IFrame(html=myhtml(name, elev), width=200, height=100)
fg.add_child(folium.Marker(location=[lat, lon], popup=folium.Popup(iframe), icon=folium.Icon(color="green")))
map.add_child(fg)
map.save("Map1Advacned.html")
添加回答
举报