问题描述
我找到了使用 https://www.naturalearthdata.com/downloads/110m-cultural-vectors/ 中的 shapefile 创建世界地图的代码 下载国家 v4.1.0
shapefile = 'data/countries_110m/ne_110m_admin_0_countries.shp'
datafile = 'data/obesity.csv'
gdf = gpd.read_file(shapefile)[['ADMIN','ADM0_A3','geometry']]
gdf.columns = ['country','country_code','geometry']
gdf.head()
country country_code geometry
0 Fiji FJI (polyGON ((180 -16.06713266364245,180 -16.555...
1 United Republic of Tanzania TZA polyGON ((33.90371119710453 -0.950000000000000...
2 Western Sahara SAH polyGON ((-8.665589565454809 27.65642588959236...
3 Canada CAN (polyGON ((-122.84 49.00000000000011,-122.974...
4 United States of America USA (polyGON ((-122.84 49.00000000000011,-120 49....
很多人使用这个文件,一切正常。
但是当我打开文件时,它只有一列'geometry'
KeyError: "['ADMIN','ADM0_A3'] not in index"
DriverError: Unable to open ne_110m_admin_0_countries.shx or ne_110m_admin_0_countries.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it.
解决方法
您好像重命名了列:
gdf.columns = ['country','country_code','geometry']
其中 admin
现在是 country
而 ADM0_A3
现在是 country_code
我解决了这个问题。要解决此错误 DriverError: Unable to open ne_110m_admin_0_countries.shx or ne_110m_admin_0_countries.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it.
我刚刚创建了一个包含 7 个不同格式的相同文件的文件夹:.cpg、.dbf、.prj、.README、.shp、.shx、.VERSION
并使用了该目录中的 .shp 文件,Jupyter 能够正确读取该文件的所有列。