使用jupyter notebook时导入文件时出错

时间:2017-12-17 23:04:23

标签: python pandas path jupyter-notebook

最近我一直在使用jupyter个笔记本,并且正在尝试使用pandas读取excel文件,它给了我以下错误:

  

FileNotFoundError:[Errno 2]没有这样的文件或目录

但它工作正常,当我在Spyder上运行时,使用完全相同的代码行读取文件。

有关如何解决此问题的任何建议?

3 个答案:

答案 0 :(得分:0)

好像是安装错误, 这样做,

对于Python 2

pip install --upgrade --force-reinstall --no-cache-dir jupyter

对于Python 3

pip3 install --upgrade --force-reinstall --no-cache-dir jupyter

答案 1 :(得分:0)

I had a similar issue in the past. After having changed the Jupyter start folder as suggested in this post: how to change jupyter start folder? , just put the excel file in this folder and to load them it isn't necessary to write the path. This is enough:

xl_file = pd.ExcelFile('myFile.xls')

答案 2 :(得分:0)

在阅读文件时提供完整路径。它正在spyder中运行,因为当你的jupyter在不同的文件夹中时,excel文件和spyder在同一个文件夹中。所以它无法读取文件。

df = pd.read_csv(full_path)