Python 创建Choropleth映射时出错,Json解码错误
我试图用Python中的Folium创建一个叶绿体图。但是有一个错误。可以找到数据Python 创建Choropleth映射时出错,Json解码错误,python,pandas,maps,choropleth,folium,Python,Pandas,Maps,Choropleth,Folium,我试图用Python中的Folium创建一个叶绿体图。但是有一个错误。可以找到数据 请注意,我尝试了所有解决此问题的建议,但没有一个对我有效。在我的案例中,错误在于choropleth函数中的geo_数据没有获得正确的值 --------------------------------------------------------------------------- JSONDecodeError Traceback (most recen
请注意,我尝试了所有解决此问题的建议,但没有一个对我有效。在我的案例中,错误在于choropleth函数中的geo_数据没有获得正确的值
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-42-ab43cadb1d56> in <module>()
8 fill_opacity=0.7,
9 line_opacity=0.2,
---> 10 legend_name='Immigration to Canada'
11 )
12
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\site-packages\folium\folium.py in choropleth(self, geo_data, data, columns, key_on, threshold_scale, fill_color, fill_opacity, line_color, line_weight, line_opacity, name, legend_name, topojson, reset, smooth_factor, highlight)
325 style_function=style_function,
326 smooth_factor=smooth_factor,
--> 327 highlight_function=highlight_function if highlight else None)
328
329 self.add_child(geo_json)
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\site-packages\folium\features.py in __init__(self, data, style_function, name, overlay, control, smooth_factor, highlight_function)
480 else: # This is a filename
481 with open(data) as f:
--> 482 self.data = json.loads(f.read())
483 elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
484 self.embed = True
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
352 parse_int is None and parse_float is None and
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
356 cls = JSONDecoder
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\json\decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\json\decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
# download countries geojson file
!wget --quiet https://ibm.box.com/shared/static/cto2qv7nx6yq19logfcissyy4euo8lho.json -O world_countries.json
print('GeoJSON file downloaded!')
world_geo = r'world_countries.json' # geojson file
# create a plain world map
world_map = folium.Map(location=[0, 0], zoom_start=2, tiles='Mapbox Bright')
# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
world_map.choropleth(
geo_data=world_geo,
data=df_can,
columns=['Country', 'Total'],
key_on='feature.properties.name',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Immigration to Canada'
)
# display map
world_map