1. 程式人生 > >python下根據csv將資料集按照類別分資料夾放置

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"