簡體   English   中英

如何去除 Choropleth map 中的黑點

[英]How to get rid of black spots in Choropleth map

我的 Choropleth map 有這些奇怪的黑點,我不確定它是否缺少數據。 我如何擺脫這些黑點?

圖片在這里

我的 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

編輯:解決了這個問題。 Folium 無法顯示北歐字母 Ä、Ö 或 Å。 不得不從我的數據中刪除它們,現在它可以工作了。

意識到我在一些城市丟失了數據。 發生這種情況是因為這些城市的名稱中有北歐字符,而 folium 無法顯示它們。 通過使用以下代碼將所有北歐字符替換為英文字母(Ä = A、Ö = O 等)來修復它:

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

還必須在 geojson 文件中手動替換它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM