pythonpandasxlsb

Using Pandas with XLSB File


Trying to read a xlsb file to create a DF in pandas.

import pandas as pd

a_data = pd.ExcelFile(
    r'C:\\Desktop\\a.xlsb')

df_data = pd.read_excel(a_data, 'Sheet1', engine='pyxlsb')
print(df.head())

When I run the script I keep getting this error.

OSError: File contains no valid workbook part


Solution

  • You can use pyxlsb, all latest version of pandas support this. Use following code:

    import pandas as pd
    a_data = pd.ExcelFile(r'C:\\Desktop\\a.xlsb')
    df = pd.read_excel('a_data', sheet_name='Sheet1', engine='pyxlsb')
    

    You will have to install pyxlsbfirst using command: pip install pyxlsb