GeoPandas 绘图功能不起作用

GeoPandas plot function not working

我在 mapshaper 上有一个看起来像这样的 shapefile:

但是当我尝试使用以下代码在 pandas 中绘制它时

police = gpd.read_file('srilanka_policestations')
police.plot()

jupyter notebook 给我一条错误消息说“AttributeError: 'str' object has no attribute 'type'”。

我不确定出了什么问题。我尝试绘制 GeoPandas 数据集 "naturalearth_cities",它工作正常。见下文:

geo-dataframe 在 pandas 中可以正常读取,但无法绘制:

非常感谢任何帮助。谢谢你们!

geopandas GeoDataFrame 中的几何列不应包含字符串,而应包含实际的几何对象。 如果有字符串,可以按如下方式转换:

import shapely.wkt
police['geometry'] = police['geometry'].apply(shapely.wkt.loads)

不过,我不得不说以上是一种解决方法,就好像你使用 geopandas read_file 读取 shapefile 一样,你不应该以字符串结尾。