我一直在使用python 3.7+和pandas的read_excel()函数将不同的excel文件读入Spyder IDE。几个月都一切正常。但是,突然之间,我突然发现文件未找到错误消息。即使文件在那里,以前可以正常工作的代码也开始产生相同的错误。为了进行调试,我创建了一个名为temp.xlsx的简单测试excel文件,并尝试使用以下命令
进行读取In: pd.read_excel('temp.xlsx')
但是,即使文件存在,我也会收到此错误
Out: Traceback (most recent call last):
File "<ipython-input-7-8b141d361f1e>", line 1, in <module>
pd.read_excel('temp.xlsx')
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\util\_decorators.py", line 178, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\util\_decorators.py", line 178, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\excel.py", line 307, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\excel.py", line 394, in __init__
self.book = xlrd.open_workbook(self._io)
File "C:\ProgramData\Anaconda3\lib\site-packages\xlrd\__init__.py", line 111, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'temp.xlsx'
任何帮助和想法将不胜感激。
答案 0 :(得分:1)
将您的temp.xlsx文件复制粘贴到包含python代码的文件夹中。
OR
pd.read_excel(“文件的完整地址”)
答案 1 :(得分:0)
我尝试读取我的xlsx文件,它可以工作。我也有python3.7 从此处下载的xlsx文件
https://github.com/irJERAD/Intro-to-Data-Science-in-Python/blob/master/MyNotebooks/scimagojr-3.xlsx
import pandas as pd
df = pd.read_excel('~/python_data_analytics/data-files/scimagojr-3.xlsx')
df.head()
Rank Country Documents Citable documents Citations Self-citations Citations
per document H index
0 1 China 127050 126767 597237 411683 4.70 138
1 2 United States 96661 94747 792274 265436 8.20 230
2 3 Japan 30504 30287 223024 61554 7.31 134
3 4 United Kingdom 20944 20357 206091 37874 9.84 139
4 5 Russian Federation 18534 18301 34266 12422 1.85 57