pandas 导入错误:在使用 pd.readexcel 读取 .xlsx 文件时安装 xlrd >= 0.9.0 以获得 Excel 支持:以前从未发生过
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51227745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: Install xlrd >= 0.9.0 for Excel support when using pd.readexcel to read .xlsx file : never happened before
提问by GusG
Something strange is going on. Just today when trying to read in a dataframe from an xlsx file:
一些奇怪的事情正在发生。就在今天,当尝试从 xlsx 文件中读取数据帧时:
import pandas as pd
df = pd.read_excel('vlnew.xlsx',sheet_name='Sheet1')
I am getting the following error: ImportError: Install xlrd >= 0.9.0 for Excel support
我收到以下错误: ImportError: Install xlrd >= 0.9.0 for Excel support
I am fully aware that plain and simple the instructions are to install xlrd, but I should not have to install xlrd when I was never getting this error before, and also, xlrd only applies to the old .xls file format. I am using .xlsx.
我完全知道简单明了的说明是安装 xlrd,但是当我以前从未收到此错误时,我不应该安装 xlrd,而且,xlrd 仅适用于旧的 .xls 文件格式。我正在使用 .xlsx。
I can't understand why today all of a sudden this error is popping up. This is very strange indeed, at least to me.
我不明白为什么今天突然出现这个错误。这确实很奇怪,至少对我来说是这样。
Update: When I execute this script in the Spyder IDE, I do not get the xlrd import error, but just today I ran this script in the Conda command prompt and only then does it report the xlrd error. Why are there inconsistencies between the Conda command prompt and Spyder IDE?
更新:当我在 Spyder IDE 中执行此脚本时,我没有收到 xlrd 导入错误,但就在今天,我在 Conda 命令提示符中运行了此脚本,然后才报告 xlrd 错误。为什么 Conda 命令提示符和 Spyder IDE 之间存在不一致?
回答by BanditoKubito
Try writing following command into the terminal
pip install xlrd
尝试将以下命令写入终端
pip install xlrd
And then import the xlrd alongside with pandas
import xlrd
and import pandas as pd
然后与大Pandas一起导入xlrd
import xlrd
和import pandas as pd
回答by Omkar
I was getting an error "ImportError: Install xlrd >= 1.0.0 for Excel support" on Pycharm for below code
对于以下代码,我在 Pycharm 上收到错误“ImportError: Install xlrd >= 1.0.0 for Excel support”
import pandas as pd
df2 = pd.read_excel("data.xlsx")
print(df2.head(3))
print(df2.tail(3))
Solution : pip install xlrd
解决方案:pip install xlrd
It resolved error after using this.
使用它后它解决了错误。
Also no need to use "import xlrd" in program
也不需要在程序中使用“import xlrd”
回答by Shikha
As mentioned by you and others correctly that xlrd needs to be installed, for using read_excel we require xlrd package.
正如您和其他人正确提到的,需要安装 xlrd,为了使用 read_excel,我们需要 xlrd 包。
This might be one of the possibility of compatibility difference between spyder and conda is that you might be using different conda environments for Spyder and prompt, one of which might contain xlrd package and other did not this has happens usually when we use different virtual environments for our work , it has happened to me many times.
这可能是 spyder 和 conda 之间兼容性差异的可能性之一是您可能对 Spyder 和 prompt 使用了不同的 conda 环境,其中一个可能包含 xlrd 包,而其他的通常在我们使用不同的虚拟环境时不会发生这种情况我们的工作,它在我身上发生过很多次。