python下根据csv将数据集按照类别分文件夹放置

代码如下:

图片地址根据实际情况修改。

import csv  
import os
import shutil
import string



csvfile = open(csvfile, 'r')
data = []
for line in csvfile:
	data.append(list(line.strip().split(',')))


for i in range(len(data)):
	if i == 0:
		continue 
	if i>=13396:
		cl = data[i][1]
		path = pic_path + str(i) +'.png'
		
		isExists = os.path.exists(path)
		if(isExists):
			newpath = new_pic_path + cl +'/' + str(i) +'.png'
			shutil.copyfile(path,newpath)    
			print 'success'
		else:
			print "not here"
 


你可能感兴趣的:(辅助代码,csv,python)