Python错误中的绘图图:初始化列表中没有参数
从以下文件中,我想使用folium:
polygons文件:? 邮政编码可变级别:?
from1(folium):
import pandas as pd
import geopandas as gpd
import folium
df_postcode_variable = pd.read_csv("postcode_sample.csv", dtype=str) # Postcode variable level
df_postcode_variable['people'] = df_postcode_variable['people'].astype(float)
df_polygons = gpd.read_file("postcode_polygons.shp") # Polygons file
df_polygons.crs = "EPSG:4326"
my_map = folium.Map(location=[41.3890727,2.1572654], zoom_start=13,
detect_retina=True, control_scale=False)
folium.Choropleth(
geo_data=df_polygons,
name='choropleth',
data=df_postcode_variable,
columns=['cp','people'],
key_on='cp',
fill_color='OrRd',
fill_opacity=0.5,
line_opacity=0.8,
line_color='Blue',
legend_name='number of people'
).add_to(my_map)
my_map
但是我会收到以下错误:
ValueError: key_on `'cp'` not found in GeoJSON.
尝试2(pandas_bokeh)工作:
import pandas_bokeh
pandas_bokeh.output_notebook()
df_joined=df_polygons.merge(df_postcode_variable.set_index('cp'), on='cp')
df_joined.plot_bokeh(simplify_shapes=20000,
category="people",
colormap="Spectral",
hovertool_columns=["cp","people"])
我如何在forium上修复此错误? CP在这两个物体中都是如此,这对我来说没有意义。看来 df_polygons
中的 cp
。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果Geodata为geopandas格式,则将密钥指定为
feature.properties.column_name
,如Geojson中。请参阅详细信息。If the geodata is in geopandas format, the key is specified as
feature.properties.column_name
, as in geojson. See this for details.此错误消息暗示您的数据中的一种意外数据类型,该数据类型导致
np.isnan
抱怨引擎盖下的某个地方,可能String
。尝试将
People
列的数据类型更改为int
:This error message hints at an unexpected data type in your data which is causing
np.isnan
to complain somewhere under the hood, probablystring
.Try changing the data type of your
people
column toint
: