I'm trying to vertically concatenate multiple shapefiles that reside in one directory, into one geodataframe. They all have the same table schema and same CRS. I am trying to use the code from this Stack Overflow post, but am getting an error 'WindowsPath' object has no attribute 'split'.
from pathlib import Path
import geopandas as gpd
import pandas as pd
folder = Path("shp")
gdf = pd.concat([
gpd.read_file(shp)
for shp in folder.glob("*.shp") ## error message points to this line ###
]).pipe(gpd.GeoDataFrame)
I'm new to programming and have spent more time than I care to admit trying to figure this one out. I'm open to using alternative Python modules as long as it ends with a geodataframe.
print(list(shapefiles))
folder.glob("*.shp")
returns anditerator
and not aniterable
. The differences is that theiterator
loads each element lazily and can only be looped through once. So if you're playing around in an interactive session and already consumed the iteration, I'd full expect the error that you're seeinggdf = pd.concat([gpd.read_file(shp) for shp in folder.glob("*.shp")]).pipe(gpd.GeoDataFrame)
. That way, you'll refresh the iterator each time you run theconcat
command