python - HTML/CSS 弹出显示列表中的文本
问题描述
是否可以在弹出方法中使用熊猫数据框(或列表)中的特定项目?
例如,而不是写:
popup = '<strong>Item</strong>'
编写自动执行此程序而不是编写 100 个弹出窗口?
popup = df.iloc[i,1]'
for i in range(100):
folium.Marker([df.iloc[i,2], df.iloc[i,3]], popup = '<strong> Location</strong>',
tooltip = tooltip, icon = folium.Icon(icon = 'cloud')).add_to(m)
解决方案
是的你可以。无需过多修改代码
for i in range(100):
folium.Marker([df.iloc[i,2], df.iloc[i,3]],
popup='<strong> {}</strong>'.format(df.iloc[i,1]),
tooltip = tooltip, icon=folium.Icon(icon='cloud')).add_to(m)
但是考虑一下其他几种流行的方法来在数据框中绘制事物。
首先使用iterrows
for _, row in df.iterrows():
folium.Marker([row['your_lat_col'], row['your_long_col'],
popup='<strong> {}</strong>'.format(row['your_popup_col']),
tooltip = tooltip, icon=folium.Icon(icon='cloud')).add_to(m)
注意:itertuples没有那么流行,但速度更快且非常相似。但是,在使用 itertuples 时,您的列名不能有空格。
此外,Python 的 zip() 使迭代变得容易
for lat, lon, popup in zip(df['your_lat_col'], df['your_long_col'], df['your_popup_col']):
folium.Marker([lat, lon, popup='<strong> {}</strong>'.format(popup),
tooltip = tooltip, icon=folium.Icon(icon='cloud')).add_to(m)
推荐阅读
- css - AjaxMin 将 CSS 与相对路径捆绑在一起
- sql - 带有 OR AND 的 Where 子句需要很长时间才能运行
- vba - OTA-缺陷评论字段值返回 HTML 标记
- java - 将结构不佳的数据转换为 json 对象
- python - 如何查询 GeoDataFrame?
- elasticsearch - Stormcrawler,状态索引和重新爬取
- c# - WPF 数据绑定与子类
- javascript - ReferenceError:ReferenceError:找不到变量:调度
- html - 如何在 Odoo 的 qWeb 报告的最后一页中只写页脚?
- video - 如何创建文件格式容器?