Importing DataFrames - no such file or directory

Viewed 8554

I am trying to import a csv file as a dataframe into a Jupyter notebook.

rest_relation = pd.read_csv('store_id_relation.csv', delimiter=',')

But I get this error

FileNotFoundError: [Errno 2] No such file or directory: 'store_id_relation.csv'

The store_id_relation.csv is definitely in the data folder, and I have tried adding data\ to the file location but I get the same error. Whats going wrong here?

enter image description here

2 Answers

Using the filename only works if the file is located in the current working directory. You can check the current working directory using os.getcwd().

import os
current_directory = os.getcwd()
print(current_directory) 

One way you can make your code work is to change the working directory to the one where the file is located.

os.chdir("Path to wherever your file is located")

Or you can substitute the filename with the full path to the file. The full path would look something like C:\Users\Documents\store_id_relation.csv.

Always try to pass the full path whenever possible

By default, read_csv looks for the file in the current working directory

Provide the full path to the read_csv function

However in your case , data and Data are different , and file paths are case sensitive

You can try the below path to fetch the file and convert it into a dataframe

rest_relation = pd.read_csv('Data\\store_id_relation.csv', delimiter=',')
Related