根据csv文件按照标签划分文件夹数据集

import csv
import shutil
import os

target_path = '.\\'#目标文件夹
original_path = '.\\train\\train\\'#原始文件夹
with open('.\\train\\train_sorted.csv',"rt", encoding="utf-8") as csvfile:
    reader = csv.reader(csvfile)
    rows= [row for row in reader]
    for row in rows:
        if os.path.exists(target_path+row[1]) :
            full_path = original_path + row[0]
            shutil.move(full_path,target_path + row[1] +'/')
        else :
            os.makedirs(target_path+row[1])
            full_path = original_path + row[0]
            shutil.move(full_path,target_path + row[1] +'/')

你可能感兴趣的:(机器学习,深度学习,分类)