Python错误集锦:pandas读取excel提示ImportError: Missing optional dependency ‘xlrd’.

您所在的位置:网站首页 python导入pandas时报错 Python错误集锦:pandas读取excel提示ImportError: Missing optional dependency ‘xlrd’.

Python错误集锦:pandas读取excel提示ImportError: Missing optional dependency ‘xlrd’.

2023-09-08 15:47| 来源: 网络整理| 查看: 265

原文链接:http://www.juzicode.com/archives/3125

 

错误提示:

用pandas read_excel()方法读取xls或xlsx文件时,提示:ImportError: Missing optional dependency ‘xlrd’. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

import numpy as np import pandas as pd df = pd.read_excel('pd-test.xls') print('df=\n',df)

命令行运行py文件提示:

Traceback (most recent call last): File "pd-test.py", line 4, in df = pd.read_excel('pd-test.xls') File "D:\Python\Python38\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper return func(*args, **kwargs) File "D:\Python\Python38\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel io = ExcelFile(io, engine=engine) File "D:\Python\Python38\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__ self._reader = self._engines[engine](self._io) File "D:\Python\Python38\lib\site-packages\pandas\io\excel\_xlrd.py", line 21, in __init__ import_optional_dependency("xlrd", extra=err_msg) File "D:\Python\Python38\lib\site-packages\pandas\compat\_optional.py", line 110, in import_optional_dependency raise ImportError(msg) from None ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

jupyter中运行提示:

 

错误原因:

1、提示没有安装xlrd模块,pip方式安装pandas时不会将xlrd作为依赖自动安装,需要手动安装xlrd模块

 

解决方法:

1、pip手动安装xlrd模块。

pip install xlrd -i https://pypi.tuna.tsinghua.edu.cn/simple import numpy as np import pandas as pd df = pd.read_excel('pd-test.xls') print('df=\n',df) df= 属性 桔子 苹果 香蕉 橙子 西瓜 0 重量 100.0 101.0 102.0 103.0 104.0 1 价格 5.3 6.3 7.3 8.3 9.3 2 体积 55.0 56.0 57.0 58.0 59.0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3