Developer
Developer

Reputation: 178

Folium library error in choropleth

Am using folium library with an open data set from kaggle,

map.choropleth(geo_path=country_geo, data=plot_data,
         columns=['CountryCode', 'Value'],
         key_on='feature.id',
         fill_color='YlGnBu', fill_opacity=0.7, line_opacity=0.2,
         legend_name=hist_indicator
          )

The above part of the code is giving me the following error:

TypeError: choropleth() got an unexpected keyword argument 'geo_path'

When I replace geo_path with geo_data I get this error:

 JSONDecodeError: Expecting value: line 7 column 1 (char 6)

Upvotes: 1

Views: 1542

Answers (2)

eliasmaxil
eliasmaxil

Reputation: 558

Is the issue related to "UCSanDiegoX: DSE200x Python for Data Science"? I took the advice of Cody and rename geo_path to geo_data at the specifications of map.choropleth. At the git hub repository, take care of using the RAW data, which is in fact a file structured with the format GeoJSON. The first two lines should start like the code provided below

{"type":"FeatureCollection","features":[
{"type":"Feature","properties":{"name":"Afghanistan"},"geometry":
{"type":"Polygon","coordinates":[[[61.210817,35.650072],.....

Upvotes: 2

Cody DIlls
Cody DIlls

Reputation: 31

geo_path doesn't work because it is not a parameter for choropleth. You are correct in replacing it with geo_data.

Your second error is likely due to non-existent or incorrectly formatted geojson file.

From http://python-visualization.github.io/folium/docs-master/modules.html?highlight=chor# your argument for geo_data needs to be a "URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON geometries".

GeoJSON formatted files follow this structure from geojson.org:

 {
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

Upvotes: 0

Related Questions