我正在尝试为公司内部营销目的创建Folium地图。地图按原样加载。但是,当我希望某个列显示在弹出文本中时,地图将无法加载。代码如下所示:
#read csv and create dataframe
df = pd.read_csv(sheet_url, delimiter=",", header=0, encoding='latin-1', engine='python')
#turn dataframe from dict into a list
csv = [list(x) for x in df.values]
#organize data into array
locations = []
for location in csv:
coords = [location[0], location[1]]
try:
locations.append({'company' : location[2], 'country' : location[3], 'products' : location[3], 'potential' : location[4], 'method' : location[13], 'note' : location[14], 'hover': f"{location[3]}<br>{location[2]}", 'click': f"<a href={location[9]}>Website</a><br>{location[13]}<br>{location[14]}", 'coordinates' : coords})
except:
print("failed because of some error")
当我尝试将 location [14] 添加到弹出窗口时,会出现问题,但在这里不会引发错误。 将标记添加到地图的迭代也不会引发错误:
for x in locations:
try:
if x['potential'] == "Current Customer":
folium.Marker(location = (x['coordinates']), popup = x['click'], tooltip = x['hover'], icon=folium.Icon(color='green')).add_to(current_cluster)
else:
folium.Marker(location = (x['coordinates']), popup = x['click'], tooltip = x['hover'], icon=folium.Icon(color='red')).add_to(potential_cluster)
except:
print("failed")
标记为“ note”的列是我遇到的问题。
到目前为止,我已经尝试过:
' '.join(map(str, location[14]))
。地图加载,文本在弹出窗口中,但用空格(L i k e t h i s
)分隔。,
更改为其他任何内容,但会产生解析器错误。每行中都有很多不同的字符,但是我不确定定界符是问题所在。Uncaught SyntaxError: Octal escape sequences are not allowed in template strings.
我认为将标记添加到地图时会发生此问题?但是没有抛出任何错误,如果我在弹出窗口中包含“注释”,则只会加载地图。任何帮助表示赞赏,谢谢。
答案 0 :(得分:0)
可能是由于字符串中的特殊字符所致。我有两个想法:
html.escape(my_string)
您可以在location[14].note
中共享确切的值吗?那肯定会帮助调试它。此外,使用浏览器的开发人员工具在控制台中查看错误消息。