2017-09-20 4 views
2

以下のコードを使用していますが、エラーが発生します。GeoJsonを使用するとPythonのコンパイル時エラーが発生する

fg_population.add_child(folium.GeoJson(data=open('world.json', 'r', encoding='utf-8-sig'), 
style_function=lambda x: {'fillColor':'green' if x['properties']['POP2005'] < 10000000 
else 'orange' if 10000000 <= x['properties']['POP2005'] < 20000000 else 'red'})) 

その後、私は取得するには、次のエラーメッセージ:ここに私のコードだ

ValueError: Unhandled object <_io.TextIOWrapper name='world.json' mode='r' encoding='utf-8-sig'>

+0

完全なスタックトレースを投稿してください。そうでなければエラーがどこから来るのかははっきりしない。また、style_functionをラムダではなく別の 'def'に分割することをお勧めします。今のようにコードを見るのはむしろ難しいです。 – viraptor

答えて

2

the docsを見ると、あなたはファイルを開くためにdata=を使用しないでください。さらに、いくつかの書式設定と分割が役立ちます。

the_world = open('world.json', 'r', encoding='utf-8-sig') 
the_style = lambda x: {'fillColor': 
          'green' if x['properties']['POP2005'] < 10000000 
         else 'orange' if 10000000 <= x['properties']['POP2005'] < 20000000 
         else 'red'} 
the_map = folium.GeoJson(the_world, style_function=the_style) 
fg_population.add_child(the_map) 
関連する問題