python-3.x - 如何使用 Pandas.read_excel 在内存中打开 XLS 文件?
问题描述
我有一个文件,我正在尝试使用 Pandas.read_excel 打开它。我收到这样的错误 -
无效文件:
InMemoryUploadedFile:file.xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
解决方案
首先,您需要使用 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())
这里“myfile”是你的内存文件
推荐阅读
- python - csv 数据文件,其中写入“bytearray(...)”
- statistics - 当两个特征与目标变量同等相关时,选择哪一个
- dispatch - bixby 必须使用命名的调度短语
- elasticsearch - Elasticsearch 中的排序和偏好
- forms - 如何使用您的 Google 表单中列出的电子邮件地址重新发送电子邮件?
- python - 在进行数据帧操作之前,我可以让熊猫转换 dtypes 吗?
- assembly - RIP 在编译时注册
- sql - 在分离正负值的同时获取多个值
- swift - 改变 SCNReferenceNode 宽高比
- minecraft - 当我添加“面对”时,/执行传送不起作用