如何使用 Pandas.read_excel 在内存中打开 XLS 文件?

Bha*_*ttu 3 xlrd xlsx python-3.x pandas

我有一个文件试图使用 Pandas.read_excel 打开。我收到这样的错误 -

无效文件:

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

Fer*_*tol 6

首先,您需要使用 xlrd 打开文件,然后使用参数 engine="xlrd" 将结果传递给 pandas.read_excel

import pandas as pd
import xlrd

book = xlrd.open_workbook(file_contents=myfile)
df = pd.read_excel(book,engine='xlrd')
print(df.head())
Run Code Online (Sandbox Code Playgroud)

这里的“myfile”是你的内存文件