Python读取 xlsb 文件格式
生活随笔
收集整理的這篇文章主要介紹了
Python读取 xlsb 文件格式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
.xlsb 格式是Binary格式存儲的excel文件,比普通的xlsx文件的體積要小很多,在數據量極大的場景比較多用。
目前有兩種方式讀取 .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庫逐行讀取數據
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文件,轉為DataFrame(詳細)
總結
以上是生活随笔為你收集整理的Python读取 xlsb 文件格式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 算法基础——递归神经网络RNN
- 下一篇: python读xlsb