vik1245
vik1245

Reputation: 556

Jupyter gives IOError for .text file

I am using Jupyter notebook to import some data from a text file.

The folder from which I have imported the notebook has another file, data.txt but when I try to use the loadtxt() module, the following error appears:

IOError                                   Traceback (most recent call last)
<ipython-input-4-a129a96139d0> in <module>()
----> 1 our_data = loadtxt("data.txt")
IOError: data.txt not found.

I looked for a solution and the manual in the notebook stated that the file may not be in the same directory or folder as your notebook.

I checked twice and found that the folder on my computer contains both the notebook and the data.txt file in the same location.

What is the issue?

Upvotes: 0

Views: 428

Answers (3)

smaftoul
smaftoul

Reputation: 2683

The file is simply not in the folder of the output of this code

import os
print(os.getcwd())

You need to either put the data.txt file in this folder or load the file with a path the points to the file.

Upvotes: 1

Santiago Bruno
Santiago Bruno

Reputation: 446

Can you try using a full path instead of just data.txt?

Maybe the current directory for jupyter is not where the notebook is.

Or you could try printing the current directory, or current directory contents like this to be sure:

import os;print(os.listdir("."))

Upvotes: 0

jihan1008
jihan1008

Reputation: 360

As far as I know, loadtxt() method is from numpy, so you should addimport numpy as np and use it as np.loadtxt().

Hope this helps!

Upvotes: 0

Related Questions