How can I create a for loop that will take specific images form a folder and copy that to another folder?

  for-loop, python

I have this table in a csv file called sample_labels.csv
In the table there is image index and class labels as such-

Image Index           labels 
00000013_005.png   Emphysima 
00000013_026.png   Emphysima 
00000017_001.png   No finding 
00000042_002.png   No finding 
00000084_000.png   Effusion 
00000099_003.png   Effusion

I have another folder with the images in them. The folder is called "train_images"

How can i create a for loop that with create folders called "Emphysima", "No finding", "Effusion" and store those images with the corresponding label in the corresponding folder?

I mean the two images with Emphysima label in "Emphysima" folder and so on.

Source: Python Questions

LEAVE A COMMENT