I am trying to open a file in jupyter notebook however i am getting the below error when i try to read as a list of lists.
I need to know what has gone wrong?
How can i know the directory of the notebook so i can paste the file to notebook directly or start a new notebook in the directory of the file i want to open?
The key is just to make sure the source file and the python jupyter notebook file are in the same folder. As long as they are together, we can read with âname.csvâ
Based on your file path it looks like youâre using Windows? In that case I would include a r in front of the file path so that Python interprets it as a raw string.
So it would look like:
open_file = open(râD:\DataQuest\Python Data Analyst\Project_1\AppleStore.csvâ)
The backslash ( â\â ) is an escape character for strings so you either have to escape it with another backslash or convert to a raw string so that the file path is read properly.
I create a set folder for Jupyter notebooks on the machine Iâm working, uncreatively I call that folder âNotebooksâ.
I then generate a jupyter config file by running this command in cmd/terminal
jupyter notebook --generate-config
In windows this places the config file âjupyter_notebook_config.pyâ in your c:\users[username].jupyter folder
On a mac(and I suspect linux) this goes in your /users/[username]/.jupyter directory.
I then edit this config to set the default path that jupyter uses to find notebooks. You do this by editing the setting labelled as follows:
c.NotebookApp.notebook_dir
ensure you use forward slashes in the directory path, not backwards.
Now when you load jupyter this will âlandâ in that folder you setup and you can be super organised.
If you want to take it a step further, I would also recommend using CookieCutter to build your new project folder structure each time. Instructions can be found here: https://github.com/drivendata/cookiecutter-data-science
A good template/structure to used can be called like so on your command line (Guide here)
The benefit of cookiecutter is that youâll use a standard directory structure which is well organised. Youâll have place to store your initial raw data, your worked on data, and your final output for example. All very important so you can always recreate your experiment.
Assuming you are replying to me, my answer is providing a solution to the users root cause of the problem. Simply telling them the bit of code to finding their file for that notebook isnât solving the underlying problem that @adel.abdallah2790 has. The OP doesnât even know where they jupyter notebook is stored on their own system even though they are working on it.
This is a fundamental bit of learning. The user should know exactly where their work files are stored otherwise their development and tests cannot be shared and reproduced. You should also learn how to control your jupyter environment to work for you. Any data analyst and Iâm sure data scientist will agree that organised and consistent approach to how you present your work is very important.
My post is helping them to setup their jupyter notebooks in their own desired location, and cookiecutter assists them to be organised with their jupyter notebook development into a layout that is well organised and well used by other people.
If I wanted to provide an exact answer to only this posted problem then Iâd point out that the problem is with the encoding of the file, not the location of the file.
You do not need to know where your laptop projects are located in order to transfer the file to the project folder. You can use Drag-on-Drop and simply drag and drop the file into the browserâs open window in jupyter
But your problem is not with the file path, but with the encoding of the data in the file.
Try explicitly specifying the required encoding when opening the file