I am working with a covid dataset right now and I have loaded all the images into a dataframe.I have labelled covid positive images as 1 and normal images as zero.I want to separate the data into two folders namely 1 (1 shall contain covid positive images) and 0(0 folder should contain normal images).Picture of the dataframe
How can I do the same? Please help. PS: I am using google colab.
CodePudding user response:
Just go through the dataframe element by element and save to a folder based on the flag:
for file, flag in zip(df['filename'], df['categories']):
if flag == 0:
#save file to first directory
elif flag == 1:
#save file to second directory