简体   繁体   中英

How to get rid of black spots in Choropleth map

My Choropleth map has these weird black spots and i'm not sure if its missing data or not. How do I get rid of those black spots?

Picture here

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

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

I'm running this on 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

Edit: Solved the issue. Folium isn't able to show nordic letters Ä, Ö or Å. Had to delete them from my data and now it works.

Realized I was missing data in some of the cities. This happens because those cities have nordic characters in their name, and folium is not able to show them. Fixed it by replacing all nordic characters with english letters (Ä = A, Ö = O etc) with following code:

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

Also had to replace them manually in the geojson file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM