這篇文章主要介紹了python中如何解決讀excel數(shù)值為浮點(diǎn)型的問(wèn)題,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
如下所示:
#讀入no data = xlrd.open_workbook("no.xlsx") #打開(kāi)excel table = data.sheet_by_name("Sheet1") #讀sheet nrows = table.nrows cols = table.ncols nos = [] for i in range(1,nrows): #指定從1開(kāi)始,到最后一列,跳過(guò)表頭 for j in range(cols): ctype = table.cell(i , j).ctype #判斷python讀取的返回類型 0 --empty,1 --string, 2 --number(都是浮點(diǎn)), 3 --date, 4 --boolean, 5 --error no = table.cell(i, j).value #獲取單元格的值 if ctype == 2 : no = str(int(no)) #將浮點(diǎn)轉(zhuǎn)換成整數(shù)再轉(zhuǎn)換成字符串 nos.append(no) print(nos)
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“python中如何解決讀excel數(shù)值為浮點(diǎn)型的問(wèn)題”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!