Python读取 xlsb 文件格式
.xlsb 格式是Binary格式存儲的excel文件,比普通的xlsx文件的體積要小很多,在數(shù)據(jù)量極大的場景比較多用。
目前有兩種方式讀取 .xlsb 格式的文件
Pandas
官方文檔:Binary Excel (.xlsb) files
The read_excel() method can also read binary Excel files using the pyxlsb module. The semantics and features for reading binary Excel files mostly match what can be done for Excel files using engine=‘pyxlsb’. pyxlsb does not recognize datetime types in files and will return floats instead.
Currently pandas only supports reading binary Excel files. Writing is not implemented.
但如果表中有合并的單元格,則在處理dataframe的時候會出錯,可以用pyxlsb庫逐行讀取數(shù)據(jù)
pyxlsb
import pyxlsb as px import pandas as pdpath = "test.xlsb" list_row=[] list_accumulate= []# 逐行讀取 with px.open_workbook(path) as wb:sheets = wb.sheetsfor sheet in sheets:row_generator = wb.get_sheet(sheet).rows()for row in row_generator:for cell in row:list_row.append(cell.v)list_accumulate.append(list_row)list_row=[]df_excel = pd.DataFrame(list_accumulate)參考來源:使用pyxlsb庫讀取xlsb格式excel文件,轉(zhuǎn)為DataFrame(詳細(xì))
總結(jié)
以上是生活随笔為你收集整理的Python读取 xlsb 文件格式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 算法基础——递归神经网络RNN
- 下一篇: 夜神模拟器安装证书