我尝试使用数据框的“ E”列将图像复制到其他目录。但是我的代码将每个图像复制到dir_0和dir_1
数据框如下所示:
A C D E
0 english_0 0 0 False
1 english_1 1 2 False
2 english_2 2 4 False
3 english_3 3 6 True
4 english_4 4 8 True
5 english_5 5 10 True
src_dir = "/Users/Downloads/copy_image_test/source_dir"
dst_dir1 = "/Users/Downloads/copy_image_test/target_dir/1"
dst_dir0 = "/Users/Downloads/copy_image_test/target_dir/0"
def split_image_to_folder(row):
for image in glob.iglob(os.path.join(src_dir, "*.png")):
if (row['E'] == 0):
shutil.copy(image, dst_dir0)
else:
shutil.copy(image, dst_dir1)
df.apply(split_image_to_folder, axis = 1)