1. Write to Excel, you do not need to create a new excel at the beginning, will automatically generate
Attribute_proba is the object I wrote.
Import XLWT = XLWT. Workbook () = Myexcel.add_sheet ('sheet') si=-1 SJ =-1 for in attribute_proba: si=si+1 for in I: sj=sj+1 sheet.write (Si,sj,str (j)) SJ=-1 myexcel.save ( "attribute_proba_big.xls"
2. Write txt, you need to create a new TXT file from the beginning
F=open ('f:/goverment/myfinalcode/predict.txt'w') for inch Range (s): f.write (str (predict[i))) f.write ('\ n') f.write (" written ") f.close ()
3. Read in CSV
File ='F:/goverment/myfinalcode/test_big.csv'fo=open (file) LS=[] forLineinchFo:line=line.replace ("\ t",",") Line=line.replace ("\ n",",") Line=line.replace ("\"",",") Ls.append (Line.split (",")) forIinchLs:li=[] forJinchI:ifj = ="': ContinueLi.append (str (j)) Testdata.append (LI)
from Import read_csv = Read_csv ("f:/goverment/excel operating/type_in.csv") = Data_ set.values[:,:] = [] for in data: = [] for line : ls.append (j) test_data.append (LS)
4. Read in XLS
Import xlrd ' F:/goverment/myfinalcode/test_big_label.xls ' = Xlrd.open_workbook (file) = Wb.sheet_by_name ("Sheet1" ) for in Range (ws.nrows): = [] for in Range (ws.ncols): col.append (Ws.cell (R, c). Value) Testlabel.append (COL)
Python writes data to Excel or TXT, read in CSV format or XLS file