Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open in memory XLS file using Pandas.read_excel?

I have a file which I am trying to open using Pandas.read_excel. I get an error like this -

invalid file:

InMemoryUploadedFile: file.xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)

like image 872
Bharat Bittu Avatar asked Sep 01 '25 22:09

Bharat Bittu


1 Answers

First you need to open your file with xlrd, then pass the result to pandas.read_excel with the parameter engine="xlrd"

import pandas as pd
import xlrd

book = xlrd.open_workbook(file_contents=myfile)
df = pd.read_excel(book,engine='xlrd')
print(df.head())

here "myfile" is your in memory file

like image 183
Fermin Pitol Avatar answered Sep 04 '25 01:09

Fermin Pitol