python建立表格並寫入內容

def output_xls(xls_path, cato, recall, prec, ap, mrecall, mprec, mAP):
    book = xlwt.Workbook() #建立一個Excel
    sheet1 = book.add_sheet('1') 
    sheet1.write(0,0,'catogory_name') 
    sheet1.write(0,1,'recall') 
    sheet1.write(0,2,'precision') 
    sheet1.write(0,3,'ap')     
    for i, label in enumerate(cato):
        sheet1.write(i+1,0,label.decode('utf-8')) #若是label是中文必定要解碼
        sheet1.write(i+1,1,recall[i]) 
        sheet1.write(i+1,2,prec[i]) 
        sheet1.write(i+1,3,ap[i]) 
    sheet1.write(i+2,0,'average') 
    sheet1.write(i+2,1, mrecall) 
    sheet1.write(i+2,2, mprec) 
    sheet1.write(i+2,3, mAP)     
    
    book.save(xls_path) #建立保存文件
相關文章
相關標籤/搜索