FileNotFoundError while importing a csv file using

2019-05-23 17:46发布

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:

import os
os.path.isfile('/home/josepm/Documents/test_ver2.csv')

and it doesn't see the file either.

3条回答
ゆ 、 Hurt°
2楼-- · 2019-05-23 18:23

Please try the following code:

import os  
path = os.path.abspath(r'file path')
f = open(path)
print(f)
查看更多
戒情不戒烟
3楼-- · 2019-05-23 18:36

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

查看更多
我想做一个坏孩纸
4楼-- · 2019-05-23 18:45

Change

pd.read_csv('\Users\user\Desktop\Workbook1.csv')

to

pd.read_csv(r'C:\Users\user\Desktop\Workbook1.csv')
查看更多
登录 后发表回答