我找到了一个使用来自https://www.naturalearthdata.com/downloads/110m-culture-vectors/ 下载国家 v4.1.0的 shapefile 的创建世界地图的代码
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.