FileNotFoundError while importing a csv file using pandas in Jupyter notebook

ぐ巨炮叔叔 提交于 2020-01-01 06:34:05

问题


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.


回答1:


Change

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

to

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



回答2:


Please try the following code:

import os  
path = os.path.abspath(r'file path')
f = open(path)
print(f)



回答3:


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



来源:https://stackoverflow.com/questions/46643768/filenotfounderror-while-importing-a-csv-file-using-pandas-in-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!