首页 > 解决方案 > 如何将文件从数据框中移动到单独的文件夹中?

问题描述

我现在正在使用一个 covid 数据集,并且我已将所有图像加载到一个数据框中。我已将 covid 正图像标记为 1,将正常图像标记为零。我想将数据分成两个文件夹,即 1(1 应包含 covid正图像)和 0(0 文件夹应包含正常图像)。数据框的图片

我怎样才能在 google colab 中做同样的事情?

标签: pythonpandasdataframe

解决方案


只需逐个元素地浏览数据框并根据标志保存到文件夹中:

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

推荐阅读