0

I have a pandas dataframe where column 1 is my file_path and column 2 is my label. Is it possible to sort the images into new directories based on the value of the labels. I am using 3 labels so the value is either 0, 1, 2.

dataframe = pd.read_csv('\\extension.csv', header = True)
if dataframe.iat[0,1] == 0:
    if not os.path.exists(dest_fold_0):
        os.mkdir(dest_fold_0)
    img.save(dest_fold_0 + dataframe.iat[1, 0], 'jpeg')

DataFrame example:

File_Extension,Labels
['\\test_0000_50x50.jpg'],0
['\\test_0001_50x50.jpg'],1
['\\test_0002_50x50.jpg'],0
['\\test_0003_50x50.jpg'],1
['\\test_0004_50x50.jpg'],2
['\\test_0005_50x50.jpg'],0
['\\test_0006_50x50.jpg'],1
rzaratx
  • 756
  • 3
  • 9
  • 29
  • You should take a look at the following https://stackoverflow.com/questions/8858008/how-to-move-a-file-in-python in particular you could do a filter to get the respective list of images for each label and then loop through executing `os.rename(source, f'{new_dir}/{filename}')` – Chinny84 Nov 06 '19 at 01:24
  • Are you looking for df.sort_values('Labels') ? – aprilangel Nov 06 '19 at 03:03

0 Answers0