我在跟随folium代码时遇到错误。我究竟做错了什么?

时间:2019-05-24 17:44:52

标签: python data-science folium

这是我第一次尝试大愚。 我的数据集中有两列,“状态”和“%_criminals”。我想在Choropleth映射上绘制这些数据。我尝试了以下代码。出现错误,我不明白。 另外,我想知道'key_on'属性的用途。

数据集名称:Total_crime_rate 我要使用的列:['state':状态名称]&['%_criminals':浮点值。]

india_map = folium.Map(location=[22.28,79.75],zoom_start = 5, tiles='Mapbox Bright')

!wget --quiet https://ibm.box.com/shared/static/cto2qv7nx6yq19logfcissyy4euo8lho.json -O world_countries.json

print('GeoJSON file downloaded!')

world_geo = r'world_countries.json'

threshold_scale = np.linspace(Total_crime_rate['%_criminals'].min(),
                              Total_crime_rate['%_criminals'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 

folium.Choropleth(
    geo_data=world_geo,
    data=Total_crime_rate,
    columns=['State', '%_criminals'],
    key_on='feature.properties.name',
    threshold_scale=threshold_scale,
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Crimes in INDIA',
    reset=True).add_to(india_map)
folium.LayerControl().add_to(india_map)
# display map
india_map

我收到以下错误。我试图用Google搜索它,但找不到解决方案。

---------------------------------------------------------------------------
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-61-0d755e6e2eec> in <module>()
      9     line_opacity=0.2,
     10     legend_name='Crimes in INDIA',
---> 11     reset=True).add_to(india_map)
     12 folium.LayerControl().add_to(india_map)
     13 # display map

/opt/conda/lib/python3.6/site-packages/folium/features.py in __init__(self, geo_data, data, columns, key_on, bins, fill_color, nan_fill_color, fill_opacity, nan_fill_opacity, line_color, line_weight, line_opacity, name, legend_name, overlay, control, show, topojson, smooth_factor, highlight, **kwargs)
   1040                 style_function=style_function,
   1041                 smooth_factor=smooth_factor,
-> 1042                 highlight_function=highlight_function if highlight else None)
   1043 
   1044         self.add_child(self.geojson)

/opt/conda/lib/python3.6/site-packages/folium/features.py in __init__(self, data, style_function, name, overlay, control, show, smooth_factor, highlight_function, tooltip)
    438             else:  # This is a filename
    439                 with open(data) as f:
--> 440                     self.data = json.loads(f.read())
    441         elif hasattr(data, '__geo_interface__'):
    442             self.embed = True

/opt/conda/lib/python3.6/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

/opt/conda/lib/python3.6/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):

/opt/conda/lib/python3.6/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)````

0 个答案:

没有答案