Python版本3.9,Geopandas版本1.0.1
问题描述:
这是执行的代码,
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.plot()
plt.show()
这是报错信息,
Traceback (most recent call last):
File "C:/Users/86191/Desktop/geopandas_测试代码.py", line 20, in <module>
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
File "D:\Python311\Lib\site-packages\geopandas\datasets\__init__.py", line 18, in get_path
raise AttributeError(error_msg)
AttributeError: The geopandas.dataset has been deprecated and was removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.
原因geopandas,在版本1.0.0已经移除了内置数据集,而我使用了geopandas.datasets.get_path('naturalearth_lowres'),这句在1.0以上版本,已经无法使用了
官方解释:https://github.com/geopandas/geopandas/issues/2751
解决方案
如果Python版本支持安装老版本,可以回退
pip install geopandas==0.14.4
如果没有办法回退,可以新增安装,通过这个调用你需要的数据集
pip install geodatasets
比如:
import geopandas
from geodatasets import get_path
import matplotlib.pyplot as plt
path_to_data = get_path("nybb")
gdf = geopandas.read_file(path_to_data)
gdf = gdf.set_index("BoroName")
gdf["area"] = gdf.area
gdf.plot("area", legend=True)
plt.show()
标签:get,Python,geopandas,naturalearth,报错,gdf,import,path,was
From: https://blog.csdn.net/qq_61523551/article/details/140877547