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

首頁 > 學院 > 開發設計 > 正文

python操作csv-xls完善后的代碼

2019-11-14 17:02:48
字體:
來源:轉載
供稿:網友
#coding:utf-8#導入相應模塊import csv,xlwt,sys,os,fnmatch,xlrdfrom xlutils.copy import copy#對xls文件中的絕對值數據求最大值并列表def max_Excel(excel):    rb1=xlrd.open_workbook(excel)    #sheet0=rb1.sheets()[1]    wb1=copy(rb1)    #sheet頁通過sheet名稱得到的才能獲取行數和列數,但是不能進行寫操作,通過下標獲得的sheet可以進行寫操作,但是不能獲得行數和列數    sheet0=rb1.sheet_by_name("Absolute")    sheet3=wb1.get_sheet(2)      nrows1=sheet0.nrows    ncols1=sheet0.ncols       for k in range(0,ncols1,):        sheet3.write(0,k,u'炸點%d' %(k+1))                    cols = sheet0.col_values(k)        cmax=max(cols[1:])               sheet3.write(1,k, cmax)      wb1.save(excel)#對xls文件中的data數據求絕對值def abs_excel(excel):    #    rb=xlrd.open_workbook(excel)    #sheet=rb.sheets()[0]    wb=copy(rb)    sheet = rb.sheet_by_name("data")    #print sheet    sheet2=wb.get_sheet(1)       nrows=sheet.nrows    ncols=sheet.ncols      for i in range(nrows):        for j in range(ncols):            w=sheet.cell(i,j).value            if (i==0):                sheet2.write(i,j,w)            else:                v = float(w)                sheet2.write(i,j,abs(v))    wb.save(excel)     max_excel(excel)#另存為xls文件def ex_file(mycsvfile):    csvfile = open(mycsvfile,"rb")    #csvfile = open("test.csv","rb")    #新建excel文件    myexcel = xlwt.Workbook()    #新建sheet頁    mysheet1= myexcel.add_sheet("data")    mysheet2= myexcel.add_sheet("Absolute")    mysheet3= myexcel.add_sheet("MAX")    #獲取csv的文件名    portion = os.path.splitext(mycsvfile)    #讀取csv中文件信息    reader = csv.reader(csvfile,dialect='excel')    l = 0    #通過循環獲取單行信息    for line in reader:        r = 0        #通過雙重循環獲取單個單元信息        for i in line:            #通過雙重循環寫入excel表格            mysheet1.write(l,r,i)            r+=1        l+=1            myexcel.save(portion[0]+".xls")    excel = portion[0]+".xls"    #print portion[0]+".xls"    abs_excel(excel)               def iterfindfiles(path, fnexp):    for root, dirs, files in os.walk(path):        for filename in fnmatch.filter(files, fnexp):            yield os.path.join(root, filename)    #批量處理if __name__=="__main__":    mypath=raw_input("Please enter a path:")    myfnexp='*.csv'    #print 1    for filename in iterfindfiles(mypath,myfnexp):        #print filename        ex_file(filename)        #abs_excel(filename)        #max_excel(filename)    raw_input ('please enter to exit')

 

最后可以通過 python pyinstaller --console --onefile  絕對路徑/py文件.py  命令生產成對應的exe文件。

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鸡西市| 苏尼特右旗| 乐陵市| 辽源市| 海南省| 中卫市| 宜宾市| 安岳县| 安吉县| 临沂市| 武乡县| 宁都县| 万年县| 句容市| 勃利县| 阿荣旗| 东港市| 临西县| 青海省| 房产| 顺义区| 海门市| 喜德县| 高雄县| 浦县| 内丘县| 高安市| 绵阳市| 筠连县| 西畴县| 吴堡县| 忻州市| 宜兰县| 清涧县| 柯坪县| 彭泽县| 抚顺市| 北流市| 平邑县| 淮安市| 永和县|