2016-03-15 49 views
1

当我尝试使用.JSON文件绘制地理CSV数据文件时,我的iPython界面出现错误。 [我的样本数据的图像] [1]使用Json文件在Python中绘制德语地理数据

这是我的Python代码:

data3=DataFrame(df['DropOffDateNumber'].groupby((df['federal_state'])).mean()).reset_index() 
state_geo = r'bundeslaender.json' 
map = folium.Map(location=[50.810356, 9.925261], zoom_start=3) 

的代码的输出如下所示:

[输出] [2]

我有2个.JSON文件我试图用来绘制地图: File1:

<a href=http://www.filedropper.com/bundeslaender><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com >file upload storage</a></div> 

文件2:

<a href=http://www.filedropper.com/databundeslander><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com >online backup</a></div> 

这里是我在iPyhton运行时代码:

map.geo_json(geo_path=state_geo, data=data3, 
      columns=['federal_state', 'DropOffDateNumber'], 
      key_on='properties.GEN', 
      fill_color='BuPu', fill_opacity=0.7, line_opacity=0.2, 
      legend_name='User Retention') 
map 

这是我收到的错误:

StopIteration        Traceback (most recent call last) 
C:\Users\Animesh Dubey\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx) 
    358   try: 
--> 359    obj, end = self.scan_once(s, idx) 
    360   except StopIteration as err: 

StopIteration: 0 

During handling of the above exception, another exception occurred: 

ValueError        Traceback (most recent call last) 
<ipython-input-46-1c66c89f704c> in <module>() 
     3    key_on='properties.GEN', 
     4    fill_color='BuPu', fill_opacity=0.7, line_opacity=0.2, 
----> 5    legend_name='User Retention') 
     6 map 
     7 #.create_map(path='us_states.html') 

C:\Users\Animesh Dubey\Anaconda3\lib\site-packages\folium\folium.py in geo_json(self, *args, **kwargs) 
    504   warnings.warn('This method is deprecated. ' 
    505      'Please use Map.choropleth instead.') 
--> 506   return self.choropleth(*args, **kwargs) 
    507 
    508  def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', 

C:\Users\Animesh Dubey\Anaconda3\lib\site-packages\folium\folium.py in choropleth(self, geo_path, geo_str, data_out, data, columns, key_on, threshold_scale, fill_color, fill_opacity, line_color, line_weight, line_opacity, legend_name, topojson, reset) 
    677    geo_json = TopoJson(geo_data, topojson, style_function=style_function) # noqa 
    678   else: 
--> 679    geo_json = GeoJson(geo_data, style_function=style_function) 
    680 
    681   self.add_children(geo_json) 

C:\Users\Animesh Dubey\Anaconda3\lib\site-packages\folium\features.py in __init__(self, data, style_function, name, overlay, control) 
    299   if hasattr(data, 'read'): 
    300    self.embed = True 
--> 301    self.data = json.load(data) 
    302   elif isinstance(data, dict): 
    303    self.embed = True 

C:\Users\Animesh Dubey\Anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 
    266   cls=cls, object_hook=object_hook, 
    267   parse_float=parse_float, parse_int=parse_int, 
--> 268   parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) 
    269 
    270 

C:\Users\Animesh Dubey\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 
    316    parse_int is None and parse_float is None and 
    317    parse_constant is None and object_pairs_hook is None and not kw): 
--> 318   return _default_decoder.decode(s) 
    319  if cls is None: 
    320   cls = JSONDecoder 

C:\Users\Animesh Dubey\Anaconda3\lib\json\decoder.py in decode(self, s, _w) 
    341 
    342   """ 
--> 343   obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
    344   end = _w(s, end).end() 
    345   if end != len(s): 

C:\Users\Animesh Dubey\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx) 
    359    obj, end = self.scan_once(s, idx) 
    360   except StopIteration as err: 
--> 361    raise ValueError(errmsg("Expecting value", s, err.value)) from None 
    362   return obj, end 

ValueError: Expecting value: line 1 column 1 (char 0) 

回答

0

我碰到这个问题就来了,因为我在尝试在Folium中做类似的事情时有这个确切的错误。在我的情况下,问题原来是state_geo json文件的格式错误。

我试图访问您链接到的json文件以检查您是否也是这种情况,但链接无效。如果你还没有解决这个问题,我建议再次检查json格式。

+0

谢谢安托尔,仍然试图解决这个问题。你能否给我你的邮件ID,我可以发送你的JSON文件来检查。 –

+0

如果您可以将它托管在某处并提供链接,我会查看一下。 – anthr

+0

https://drive.google.com/file/d/0B9Kd2946W9HOR3ExNWN3YVBqOGM/view?usp=sharing –