'Python Script to find file names from CSV will not concatenate

I am writing a script that will allow me to extract a segment of image files from a large folder. I put the image file names into a dataframe. I am having problems figuring out how to iterate through the list, find the corresponding file name and add .img on the end as these are image files before moving it into the destination folder. I'd appreciate any feedback.

import pandas as pd
import os
import shutil

data = pd.read_csv('Tiles_Filtered.csv')

df = pd.DataFrame(data, columns = ['Tile_Name'])
print(df)


source_directory = 'C:\\Users\\newScript\\DEM_IMGs'
destination_directory = 'C:\\Users\\\newScript\\DEM_IM_Filtered'

for index, row in df.iterrows():
    source_file = source_directory + image
    destination_file = destination_directory + image
    os.copy(source_file, destination_file)


Solution 1:[1]

This one is hard for me to test because of the paths and me not actually having images... but give it a try. If nothing else, it might get you closer.

Also note that this is assumes your images already have ".img" at end of it in the source, if not... and you need to add that, then let me know and I can adjust to suit.

import pandas as pd
import os
import shutil

data = pd.read_csv('Tiles_Filtered.csv')

df = pd.DataFrame(data, columns = ['Tile_Name'])
print(df)


source_directory = r'C:\Users\newScript\DEM_IMGs'
destination_directory = r'C:\Users\newScript\DEM_IM_Filtered'

for i in df['Tile Name']:
    source_file = os.path.join(source_directory, i)
    destination_file = os.path.join(destination_directory, i)
    shutil.copy(source_file, destination_file)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 systematical