折腾:
【未解决】Python中用pandas读取excel文件并解析得到数据
期间,用代码:
import pandas as pd salePd = pd.read_excel(io=RelationFullPath)
结果报错:
发生异常: ImportError Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

看来是:缺少安装对应的库了xlrd
即pandas所依赖的,读取exce的库
不过此处打算,换成openpyxl
pandas read excel openpyxl
pandas read_excel
pandas.read_excel(io, sheet_name=0, header=0, names=None, index_col=None, usecols=None, squeeze=False, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skiprows=None, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, parse_dates=False, date_parser=None, thousands=None, comment=None, skipfooter=0, convert_float=True, mangle_dupe_cols=True, storage_options=None)
其中是有:
- engine参数的
pipenv install openpyxl Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning. Installing openpyxl... Adding openpyxl to Pipfile's [packages]... ✔ Installation Succeeded Pipfile.lock (1b8c22) out of date, updating to (6415b7)... Locking [dev-packages] dependencies... Locking [packages] dependencies... Building requirements... Resolving dependencies... ✔ Success! Updated Pipfile.lock (6415b7)! Installing dependencies from Pipfile.lock (6415b7)... 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
用代码:
salePd = pd.read_excel(io=RelationFullPath, engine="openpyxl")
结果:

真的可以了。
【总结】
此处代码:
salePd = pd.read_excel(io=RelationFullPath)
报错:
Missing optional dependency ‘xlrd’
原因:pandas,对于读取excel,默认用的底层引擎engine是xrld
解决办法:去安装对应的,默认的engine:xlrd
或者,安装别的excel的库,然后指定engine为该库
比如此处选择用openpyxl,代码是:
salePd = pd.read_excel(io=RelationFullPath, engine="openpyxl")
即可。
转载请注明:在路上 » 【已解决】pandas的read_excel报错:ImportError Missing optional dependency xlrd