I found a code for creating the worldmap that uses the shapefile from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/ Download Countries 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....
Many people use this file, and everything is ok.
But when I open the file, it only has one column 'geometry'
KeyError: "['ADMIN', 'ADM0_A3'] not in index"
And I can't understand if something is wrong with the file, or is it something wrong with the code?
Update. I think the problem is with this error. Sometimes this works, sometimes this error appears
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.
It seems like you renamed the columns:
gdf.columns = ['country', 'country_code', 'geometry']
where
admin
is nowcountry
andADM0_A3
is nowcountry_code