简体   繁体   中英

How to move files from a dataframe into separate folders?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM