I have a list of geodataframes which I imported from a folder full of shapefiles:
import glob
import geopandas as gpd
shapefiles = glob.iglob('E:/folder/shapefiles/*.shp')
gdfs = [gpd.read_file(file) for file in shapefiles]
I then clipped them all:
clipped = [gpd.clip(shapefiles, boundary) for shapefiles in gdfs]
Now I need to save each geodataframe (list item) from the list to a shapefile of its correct name in an output folder. I used this code to create another list called filenames of the shapefiles names with the .shp at the end:
filenames = []
for names in items:
if names.endswith(".shp"):
filenames.append(names)
print(filenames)
But I dont know how to save each item in the clipped list of geodataframes using its corresponding name from the filenames list
Basically I want to perform this task:
clipped[0].to_file("E:/test_output/"+filenames[0])
clipped[1].to_file("E:/test_output/"+filenames[1])
clipped[2].to_file("E:/test_output/"+filenames[2])
etc etc
But to perform it iteratively and automatically. I need something like this:
for things in clipped:
things.to_file("E:/test_output"+(for stuff in filenames return filenames[]))
but with correct syntax and that actually works.