Folium 中的货币 GeoJsonTooltip 格式
Currency GeoJsonTooltip formatting in Folium
我正在尝试在 Folium 中格式化 GeoJsonTooltip 以将整数显示为货币(千位以逗号分隔,末尾为 'Kč' 字符串。)
示例:
INPUT: 1250000
WANTED OUTPUT: 1,250,000 Kč
我无法在 Python 中通过字符串格式执行此操作,因为 GeoJsonTooltip 无法显示字符串工具提示并以以下错误结束:
(TypeError: ufunc 'isnan' not supported for the input types, and the
inputs could not be safely coerced to any supported types according to
the casting rule ''safe'')
我还没有想出解决这个问题的方法。
创建地图的代码:
map_choropleth = folium.Map(location=[49.724,15.534],tiles='cartodbpositron', zoom_start=8, min_zoom=8, max_zoom=8, zoom_control=False)
choropleth = folium.Choropleth(geo_data = geojson_countries,
data = kraj_stats,
columns=['NAZEV_NUTS', 'cena_m2_mean'],
key_on='properties.NAZEV_NUTS',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Cena za m2 v Kč'
).add_to(map_choropleth)
choropleth.geojson.add_child(folium.features.GeoJsonTooltip(
fields=['NAZEV_NUTS','cena_mean', 'cena_m2_mean'],
aliases=['Název kraje', 'Průměrná cena', 'Průměrná cena za m2'],
style=('background-color: grey; color: white;')
)
)
map_choropleth.save("mymap.html")
这是我目前拥有的:
有人能帮忙吗?
我无法在 CZK 中设置货币格式,但我能够使用 localize=True 设置数字间距。
map_choropleth = folium.Map(location=[49.724,15.534],tiles='cartodbpositron', zoom_start=8, min_zoom=8, max_zoom=8, zoom_control=False)
choropleth = folium.Choropleth(geo_data = geojson_countries,
data = merged_areas,
columns=['NAZEV_LAU1', 'cena_m2_mean'],
key_on='properties.NAZEV_LAU1',
fill_color='YlGn',
fill_opacity=0.85,
line_opacity=0.2,
legend_name='Cena za m2 v Kč'
).add_to(map_choropleth)
choropleth.geojson.add_child(folium.features.GeoJsonTooltip(
fields=['NAZEV_LAU1','cena_mean', 'cena_m2_mean'],
aliases=['Název okresu', 'Průměrná cena [Kč]', 'Průměrná cena za m2 [Kč]'],
style=('background-color: grey; color: white;'),
localize=True
)
)
map_choropleth.save("mymap_okresy.html")
我正在尝试在 Folium 中格式化 GeoJsonTooltip 以将整数显示为货币(千位以逗号分隔,末尾为 'Kč' 字符串。) 示例:
INPUT: 1250000
WANTED OUTPUT: 1,250,000 Kč
我无法在 Python 中通过字符串格式执行此操作,因为 GeoJsonTooltip 无法显示字符串工具提示并以以下错误结束:
(TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'')
我还没有想出解决这个问题的方法。 创建地图的代码:
map_choropleth = folium.Map(location=[49.724,15.534],tiles='cartodbpositron', zoom_start=8, min_zoom=8, max_zoom=8, zoom_control=False)
choropleth = folium.Choropleth(geo_data = geojson_countries,
data = kraj_stats,
columns=['NAZEV_NUTS', 'cena_m2_mean'],
key_on='properties.NAZEV_NUTS',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Cena za m2 v Kč'
).add_to(map_choropleth)
choropleth.geojson.add_child(folium.features.GeoJsonTooltip(
fields=['NAZEV_NUTS','cena_mean', 'cena_m2_mean'],
aliases=['Název kraje', 'Průměrná cena', 'Průměrná cena za m2'],
style=('background-color: grey; color: white;')
)
)
map_choropleth.save("mymap.html")
这是我目前拥有的:
有人能帮忙吗?
我无法在 CZK 中设置货币格式,但我能够使用 localize=True 设置数字间距。
map_choropleth = folium.Map(location=[49.724,15.534],tiles='cartodbpositron', zoom_start=8, min_zoom=8, max_zoom=8, zoom_control=False)
choropleth = folium.Choropleth(geo_data = geojson_countries,
data = merged_areas,
columns=['NAZEV_LAU1', 'cena_m2_mean'],
key_on='properties.NAZEV_LAU1',
fill_color='YlGn',
fill_opacity=0.85,
line_opacity=0.2,
legend_name='Cena za m2 v Kč'
).add_to(map_choropleth)
choropleth.geojson.add_child(folium.features.GeoJsonTooltip(
fields=['NAZEV_LAU1','cena_mean', 'cena_m2_mean'],
aliases=['Název okresu', 'Průměrná cena [Kč]', 'Průměrná cena za m2 [Kč]'],
style=('background-color: grey; color: white;'),
localize=True
)
)
map_choropleth.save("mymap_okresy.html")