I have a pandas dataframe df which looks like this
df = {'Regions': {0: 'REGION1', 1: 'REGION2'}, 'x': {0: '1249-43,1269-12,1280-12', 1: '1267-12,1269-12,1280-12'}}
and a list of raster files called rasters
rasters = 'SI_1206-33_50cm.tif', 'SI_1249-43_50cm.tif', 'SI_1269-12_50cm.tif', 'SI_1267-12_50cm.tif', 'SI_3865-17_50cm.tif'
What I'd like to do is to create a new list of all entries in rasters that match the strings in df.x per region.
for index, row in df.iterrows():
region = row['Regions']
tiffs = row['x']
rasterlist = []
for raster in rasters:
if raster in tiffs:
rasterlist = rasterlist.append(raster)
print(rasterlist)
As a result when iterating over rasters, I am attempting to get for the first iteration a rasterlist containing 'SI_1249-43_50cm.tif' and 'SI_1269-12_50cm.tif' for REGION1 and for the second iteration a rasterlist containing only 'SI_1267-12_50cm.tif' for REGION2. The list rasterlist I would like to use as input for further processing using the MosaicToNewRaster_management fucntion in arcpy.
What does not seem to work with this code is the pattern matching, I get an empty rasterlist variable for each iteration. I assume this is the case because the different list items in df.x are separated by a comma and the in function does not seem to work. This is where I am stuck and hoping to get some input.
