我试着像往常一样运行我的库"pandas“,但后来我遇到了一个错误。
import pandas as pd
DF_temp = pd.read_excel("example.xlsx")
输出
File "/opt/anaconda3/lib/python3.7/site-packages/xlrd/__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^
SyntaxError: invalid syntax
我正在使用python 3.7
我再次安装了xlrd,但同样的问题出现了。我该如何解决这个问题?谢谢
发布于 2020-10-04 05:21:31
我也有同样的问题,并使用了建议的修复python3 -m pip install --尽管我收到了一些警告,但升级xlrd仍然适用于我。
Defaulting to user installation because normal site-packages is not writeable
Collecting xlrd
Downloading xlrd-1.2.0-py2.py3-none-any.whl (103 kB)
|████████████████████████████████| 103 kB 6.0 MB/s eta 0:00:01
Installing collected packages: xlrd
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
camelot 12.6.29 requires SQLAlchemy<0.8.0,>=0.7.7, but you'll have sqlalchemy 1.3.14 which is incompatible.
camelot 12.6.29 requires xlrd==0.7.1, but you'll have xlrd 1.2.0 which is incompatible.
Successfully installed xlrd-1.2.0
Note: you may need to restart the kernel to use updated packages.
发布于 2021-09-07 08:34:37
有时我们应该在安装任何新的包之前升级我们的pip。您可以执行以下命令:
python.exe -m pip install --upgrade pip
之后,您可以使用以下命令安装xlrd包:
pip install xlrd
即使在安装xlrd之后,您也可能会一次又一次地遇到同样的错误,请检查您的excel文件的扩展名是否正确。很多时候旧版本的excel会抛出错误。它可以是'excel 5.0/95‘文件。
对于此文件,您可以安装pyexcel或pyexcel_xls包以进行后续工作。您可以在link中找到相同的文档
使用命令:
pip install pyexcel
或
pip install pyexcel_xls
我不确定这是否会完美地工作,但是,我们可以提前探索解决这样的错误和问题。
发布于 2021-09-07 13:25:05
您似乎正在尝试读取“Microsoft Excel 97-2003工作表”类型。
尝试使用xlrd包打开工作簿,然后使用pandas read_excel函数读取它。
下面是代码片段
wb = xlrd.open_workbook(file, logfile=open(devnull, 'w'))
df = df.append(pd.read_excel(wb, dtype=str, skiprows=1, engine='xlrd'), ignore_index=True)
https://stackoverflow.com/questions/63368983
复制相似问题