python - 如何将文件从数据框中移动到单独的文件夹中?
问题描述
我现在正在使用一个 covid 数据集,并且我已将所有图像加载到一个数据框中。我已将 covid 正图像标记为 1,将正常图像标记为零。我想将数据分成两个文件夹,即 1(1 应包含 covid正图像)和 0(0 文件夹应包含正常图像)。数据框的图片
我怎样才能在 google colab 中做同样的事情?
解决方案
只需逐个元素地浏览数据框并根据标志保存到文件夹中:
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
推荐阅读
- php - Codeigniter 4 - 如何自动加载自定义配置文件?
- wpf - WPF:如何在我的列表视图项单击中绑定来自 MouseLeftButtonUp 事件的 m 对象属性
- python-3.x - 如何忽略关键错误并继续 while 循环
- google-apps-script - 当用户删除电子表格插件时,随插件添加的文档属性存储是否继续保留?
- javascript - 无法在 Three.js 中加载本地纹理,在 vue.js 中运行三个作为组件
- git - 在单分支 git 树上使用还原命令时发生冲突错误
- ios - 有人发现 UIDatePicker 在 iOS 14 下被破坏了吗?
- youtube-api - 如何从 YouTube 搜索 api(V3) 中仅获取免费视频?
- influxdb - 如何替换 Telegraf 的默认时间戳?
- sql - 在 sparksql 中将 dd-mmm-yyyy 转换为 yyyy-mm-dd