国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Python批量處理CSV文件

2019-11-14 17:39:27
字體:
供稿:網(wǎng)友
#encoding: utf-8__author__ = 'DELL'import csvimport globimport datetimeimport sysimport osreload(sys)#中文錯(cuò)誤sys.setdefaultencoding( "utf-8" )'''@author likehua    CSV批處理'''class BatchPRocessCSV:    def __init__(self,inputfolder="c://input//",outputfolder="c://output//"):        self.inputfolder=inputfolder        self.outputfolder=outputfolder    #批處理    def doBatchAction(self):        startTime=datetime.datetime.now()        print(u"開始處理...")        if (os.path.exists(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"處理完成,耗時(shí):%f秒"%(endTime-startTime).seconds)    #讀取一個(gè)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)        #讀取列 將字符串轉(zhuǎn)為數(shù)組        column=csvfile.readline().split(",")        #print(column.index('App Release Date'))        #print(column)        writer.writerow(['Rank' ,'Category', 'Country ','App Name', 'Value', 'Unit' , 'App Release Date', 'Publisher Name', 'Company Name', 'Parent Company Name'])        reader = csv.reader(csvfile)        #table = 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.writerow([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()

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 辽宁省| 仙桃市| 叶城县| 来安县| 民乐县| 北票市| 亳州市| 洛阳市| 阳江市| 克什克腾旗| 四子王旗| 海南省| 老河口市| 綦江县| 雷州市| 墨脱县| 右玉县| 海原县| 新宁县| 定结县| 承德市| 故城县| 鸡泽县| 砀山县| 寻甸| 沂水县| 正定县| 米林县| 南昌市| 外汇| 北安市| 涡阳县| 甘孜| 柳江县| 南投市| 历史| 绍兴市| 清镇市| 六安市| 卫辉市| 通化县|