货币GeoJSONTOLTIP格式(以对开本为单位)

2024-05-16 15:50:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将GeoJSONTOLTIP格式化为Folium格式,以将整数显示为货币(以逗号和结尾的“Kč”字符串分隔千) 例如:

INPUT: 1250000

WANTED OUTPUT: 1,250,000 Kč

我无法通过字符串格式在Python中实现这一点,因为GeoJSONTOLTIP无法显示字符串工具提示,并最终导致以下错误:

(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")

这就是我目前拥有的:

enter image description here

有人能帮忙吗


Tags: theto字符串map格式meancolornuts
1条回答
网友
1楼 · 发布于 2024-05-16 15:50:51

我无法在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")

相关问题 更多 >