如何消除Choropleth地图中的黑点

2024-09-30 04:32:11 发布

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

我的Choropleth地图上有这些奇怪的黑点,我不确定它是否丢失了数据。我该如何去除这些黑点

Picture here

我的csv:https://drive.google.com/file/d/10FULaQ7f4lfWdPpk4bzwlD9yymGrL14d/view?usp=sharing

我的GeoJson:https://drive.google.com/file/d/1GZljNjbIXsx55xopN9_DDlOb0Pi9Eclz/view?usp=sharing

我在Jupyter上运行这个:

    # CHOROPLETH MAP
import json
kunnat_geo = r'kuntarajat.geojson'
with open(kunnat_geo) as kunnat_file:
    kunnat_json = json.load(kunnat_file,encoding='utf8')
type(kunnat_json)

df = pd.read_csv('cleandata.csv')


map = folium.Map(location=[65,26], zoom_start=4, tiles='openstreetmap')
map.choropleth(geo_data=kunnat_geo,
             data=df, # my dataset
             columns=['Kunta', 'data'], 
             key_on='feature.properties.Name',
             fill_color='OrRd', fill_opacity=0.7, line_opacity=0.2,
             legend_name='Mielenterveyden kuntoutuskotien asiakkaat vuonna 2018',
             smooth_factor=0)

marker_cluster = MarkerCluster().add_to(map)
for i in range(0,len(coords)):

    folium.Marker([coords.iloc[i]['lat'], coords.iloc[i]['lng']], popup=coords.iloc[i]['data'],tooltip='Mielenterveyden kuntoutuskotien asiakkaat vuonna 2018').add_to(marker_cluster)
coords.head()

map.save('Choropleth.html')
map

编辑:解决了这个问题。叶状体不能显示北欧字母Ä、Ö或Å。必须从我的数据中删除它们,现在它可以工作了


Tags: csv数据httpsjsonmapdatagoogledrive
1条回答
网友
1楼 · 发布于 2024-09-30 04:32:11

意识到我在一些城市丢失了数据。这是因为这些城市的名字中有北欧文字,而folium无法显示它们。通过将所有北欧字符替换为英文字母(Ä=A、Ö=O等)并使用以下代码修复此问题:

dictionary={'ä':'a','ö':'o','Ä':'A','å':'a'}
df.replace(dictionary, regex=True, inplace=True)

还必须在geojson文件中手动替换它们

相关问题 更多 >

    热门问题