在 Jupyter 笔记本中使用 Pandas 导入 csv 文件时出现 FileNotFoundError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46643768/
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
FileNotFoundError while importing a csv file using pandas in Jupyter notebook
提问by Josep M Domingo
Screenshot of the described error.
import pandas as pd
df = pd.read_csv('/home/josepm/Documents/test_ver2.csv')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-3-5cd7fd573fb7> in <module>()
1 import pandas as pd
----> 2 df = pd.read_csv('/home/josepm/Documents/test_ver2.csv')
I try to import a CSV file using pandas and every time it says that it doesn't find the file. It's like Jupyter doesn't see it. I tried to do this:
我尝试使用 Pandas 导入一个 CSV 文件,但每次它都说找不到该文件时。就像 Jupyter 没有看到它。我试图这样做:
import os
os.path.isfile('/home/josepm/Documents/test_ver2.csv')
and it doesn't see the file either.
它也没有看到该文件。
采纳答案by Chankey Pathak
Change
改变
pd.read_csv('\Users\user\Desktop\Workbook1.csv')
to
到
pd.read_csv(r'C:\Users\user\Desktop\Workbook1.csv')
回答by S. HU
Please try the following code:
请尝试以下代码:
import os
path = os.path.abspath(r'file path')
f = open(path)
print(f)
回答by S. HU
The working directory is the point from where all the files are accessed in Jupyter Notebook.
Find the current working directory
import os
os.getcwd()
Example o/p : 'C:\Users\xyz'
Now place your CSV files in this path
List the contents of your directory to check if the CSV file is present
os.listdir('C:\Users\xyz')
Now try reading the CSV file
工作目录是 Jupyter Notebook 中所有文件的访问点。
查找当前工作目录
导入操作系统
os.getcwd()
示例 o/p : 'C:\Users\xyz'
现在将您的 CSV 文件放在此路径中
列出目录的内容以检查 CSV 文件是否存在
os.listdir('C:\Users\xyz')
现在尝试读取 CSV 文件