0

I am a beginner with Jupyter Notebook but here's what I am having trouble with:

I have created a Python3 file using Jupyter Notebook and have imported my csv file using read_csv.

Then, I created a new folder (named Park )- that would include my python file, and the csv file needed (named MyFile.csv). The purpose is to be able to run the python file from any computer- not just my own- using this relative path.

So, I do:

  import pandas as pd
  data=pd.read_csv('Park/MyFile.csv')
  data.head()

And I get this error:

No such file or directory: 'Park/MyFile.csv'.

On the contrary, when I simply run this:

   import pandas as pd
   data=pd.read_csv('MyFile.csv')
   data.head()

It runs fine. But will this work (only including the file's name) when I try to run the Python file from other computers?

All I am trying to do is to be able to send out the folder (as zipped maybe?) and have it run smoothly in any computer using a relative path for the csv files.

Any suggestion would be appreciated.

Thanks!

1
  • there are many questions which show how to create path to script folder - BASE = os.path.dirname(os.path.abspath(__file__)) and later use it to create absolute path for file os.path.join(BASE, 'Park', 'MyFile.csv'). And this resolve problem with running code on different computers. But I don't know if it will work with Jupyter because it may not have __file__ Commented Oct 31, 2021 at 10:36

1 Answer 1

2

This problem comes from the relative path of your system. If you want to run another file under the same directory, you could use "./Myfile.csv".

The "./" stands for father directory of this file - that is the current directory, so it will search file under current directory.

If you input "Park/Myfile.csv", the interpreter will search for "Park" file under current "Park" directory and ends up none existing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.