I have a folder with about 600,000 photos in it. I need to move a select 500 of those photos. I have a dataframe with those file paths as values in one of the columns. I need to be able to loop through that data frame, pluck out the specific image and set it in another folder.
The path is the full path to include the file. There is also a file column that has just the file name.
The following is an example of the data frame:
import pandas as pd
dict1 = {'path': ['D:\\images\\train\\roof\\1.jpg', 'D:\\images\\train\\roof\\2.jpg', 'D:\\images\\train\\roof\\3.jpg'
,'D:\\images\\train\\roof\\4.jpg', 'D:\\images\\train\\roof\\5.jpg'],
'image': ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg',]}
df = pd.DataFrame(dict1)
df
The following is what I tried. It's a modified version of moving files based on a wild card.
import os
import shutil
import fnmatch
def gen_find(filepat,top):
for path, dirlist, filelist in os.walk(top):
for name in fnmatch.filter(filelist,filepat):
yield os.path.join(path,name)
if __name__ == '__main__':
src = df['path'] # input
dst = 'D:\\images\\Sample' # desired location
filesToMove = gen_find(src)
for name in filesToMove:
shutil.move(name, dst)
I also tried the following:
if __name__ == '__main__':
src = 'D:\\images\\train\\roof\\'+df['image'] # input
dst = 'D:\\images\\Sample' # desired location
filesToMove = gen_find(src)
for name in filesToMove:
shutil.move(name, dst)