#encoding: utf-8__author__ = ' DELL ' import csvimport globimport datetimeimport sysimport osreload (SYS) # Chinese error sys.setdefaultencoding ("Utf-8") ' @author Likehua csv Batch ' class Batchprocesscsv:def __init__ (Self,inputfolde R= "c:\\input\\", outputfolder= "c:\\output\\"): Self.inputfolder=inputfolder Self.outputfolder=outputfolder #批处理 def dobatchaction (self): Starttime=datetime.datetime.now () Print (u "start processing ...") if (Os.path.exi STS (Self.outputfolder) ==false): #pass os.makedirs (self.outputfolder) List_dirs = Os.walk (self . inputfolder) for root, dirs, files in List_dirs: #print I for file in files: Otput=self.outputfolder+file self.readcsv2csv (self.inputfolder+file,otput) print (U "Running ... \ n ") Endtime=datetime.datetime.now () Print (U" processing completed, Time:%f sec "% (endtime-starttime). Secon--------- DS) #读取一个csv提取部分信息生成新的CSV def readcsv2CSV (self,inputfile,outputfile): With open (Inputfile, ' RB ') as Csvfile:o=open (OutputFile, "WB") #解决csv浏览乱码问题 O.write (' \XEF\XBB\XBF '); Writer=csv.writer (o) #读取列 Convert the string to array Column=csvfile.readline (). Split (",") #print (Column.index (' App rele ASE Date ') #print (column) Writer.writerow ([' Rank ', ' Category ', ' country ', ' App Name ', ' Value ', ' Unit ', ' Ap P Release Date ', ' Publisher name ', ' Company name ', ' Parent company name '] reader = Csv.reader (csvfile) #tab Le = reader[0] #Rank, Category, Store, Device, Type, Country, Period,version, app_id, App_name, Value, Unit, Value_ Type, AppUrl, App_iap, App_category, App_device, Current_price, App_release_date, publisher_id, Publisher_Name, CompanyName, Parentcompanyname, appnameunified, Appfranchise, Unifiedappid, Appfranchiseid, CompanyID, Parentcompanyid for row in Reader:lenth=len (row) if Lenth>10:writer.write Row ([Row[column. Index ("Rank")],row[column.index ("Category")],row[column.index ("Country")],row[column.index ("App Name")],row[ Column.index ("Value")],row[column.index ("Unit")],row[column.index ("App Release Date")],row[column.index (" Publisher name ")],row[column.index (" Company name ")],row[column.index (" Parent company Name ")]) #processif __name__== "__main__": Csvprocess=batchprocesscsv ("c:\\input\\", "e:\\output\\") csvprocess.dobatchaction ()