pandas读取xlsx文件报错:Excel xlsx file; not supported

在尝试使用Pandas的read_excel函数读取xlsx文件时遇到了Excelxlsxfile;notsupported错误。首先尝试通过安装xlrd特定版本(1.2.0)来解决,但该方法无效。然后,通过指定引擎参数engine为openpyxl,成功地用openpyxl库读取了xlsx文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


在使用pandas读取xlsx文件时,报错:Excel xlsx file; not supported

import pandas as pd

df = pd.read_excel('../datas/1.xlsx')

报错:


Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
XLRDError                                 Traceback (most recent call last)
 in 
······
    865         self._io = stringify_path(path_or_buffer)
    866 
--> 867         self._reader = self._engines[engine](self._io)
    868 
    869     def __fspath__(self):
...
     39     @property

d:\develop\learning\installed\Python36\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)

XLRDError: Excel xlsx file; not supported


解决

  1. 安装xlrd时指定版本
    pip install xlrd==1.2.0
但是这个我使用后未能解决,g!

  1. 指定engine

安装openpyxl
pip install openpyxl


df = df = pd.read_excel('../datas/1.xlsx', engine="openpyxl")

.

			姓名	年龄	性别	身高
	0		田		18		男		170
	1		王		16		男		175
	2		王二	17		男		181
	3		卢一	15		男		185
	4		王三	16		女		158
	5		卡特	18		女		170
ok了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值