Skip to content

an unexpected error with the 'shapefile' #3

Open

Description

@tomaszek0

I have encountered an error while trying to load a shapefile with world coordinates "ne_110m_admin_0_countries.shp" and the corresponding .shx (v5.1.1). I followed the code in your 'obesity.ipnyb' file, which included the following code:

import geopandas as gpd
shapefile = 'countries_110m/ne_110m_admin_0_countries.shp'
gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]

However, when I executed this code, I received the following error: "KeyError: "['ADMIN', 'ADM0_A3'] not in index".
I also tried loading shapefile v4.0.1, but encountered the same error.
When I loaded the file using the following code, it only contained the 'geometry' column:

gdf = gpd.read_file(shapefile)
gdf.head()

Activity

  1. tomaszek0 commented on Feb 7, 2024

    @tomaszek0
    Author

    Ah, I figured it out - I need the entire geodata archive unpacked - not individual shp and shx files.

    shapefile = 'geodata\ne_110m_admin_0_countries.shp'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions