I’m trying to create an interactive map using this guide: This
I use pycharm with anaconda environment, so I don’t understand when put my .shp file. This is the example code:
import geopandas as gpd shapefile = 'data/countries_110m/ne_110m_admin_0_countries.shp' #Read shapefile using Geopandas gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
Is this correct my directory?
C:UsersgpontPycharmProjectspythonProject2dataMapmap1ne_110m_admin_0_countries.shp
Error:
C:Usersgpontanaconda3envspythonProject2python.exe C:/Users/gpont/PycharmProjects/pythonProject2/main.py Traceback (most recent call last): File "fiona/_shim.pyx", line 83, in fiona._shim.gdal_open_vector File "fiona/_err.pyx", line 270, in fiona._err.exc_wrap_pointer fiona._err.CPLE_OpenFailedError: 'map1 e_110m_admin_0_countries.shp' does not exist in the file system, and is not recognized as a supported dataset name. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/gpont/PycharmProjects/pythonProject2/main.py", line 6, in <module> gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']] File "C:Usersgpontanaconda3envspythonProject2libsite-packagesgeopandasiofile.py", line 96, in _read_file with reader(path_or_bytes, **kwargs) as features: File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfionaenv.py", line 398, in wrapper return f(*args, **kwargs) File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfiona__init__.py", line 253, in open c = Collection(path, mode, driver=driver, encoding=encoding, File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfionacollection.py", line 154, in __init__ self.session.start(self, **kwargs) File "fiona/ogrext.pyx", line 484, in fiona.ogrext.Session.start File "fiona/_shim.pyx", line 90, in fiona._shim.gdal_open_vector fiona.errors.DriverError: 'map1 e_110m_admin_0_countries.shp' does not exist in the file system, and is not recognized as a supported dataset name. Process finished with exit code 1
Thank you in advance.
Giovanni
Advertisement
Answer
You seem to have a n
in your path, which is interpreted as a newline character. (Note the missing n
in 'map1 e_110m_admin_0_countries.shp' does not exist
)
Try
import os ... gpd.read_file(os.path.normpath(shapefile))