Reputation: 363
Hi i'm trying to work on python, and since i'm still a newbie ( but with great ambition :) ) i tend to have this error when I try to import a .txt file using the function np.genfromtxt() somehow it doesn't recognize the file, I made sure to specify the directory and everything but still getting the same error, if you could help that would be great thank you !
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import os
from sklearn.preprocessing import StandardScaler, MinMaxScaler
DATADIR = "wave_data/"
np.genfromtxt('signal_1.txt',delimiter=',')
Just so you know, wave_data is the folder containing all signal_i.txt files Here is the error :
--------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-6-17c352b5ef2d> in <module>()
----> 1 np.genfromtxt('signal_1.txt',delimiter=',')
/usr/lib/python2.7/dist-packages/numpy/lib/npyio.pyc in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows)
1547 if isinstance(fname, basestring):
1548 if sys.version_info[0] == 2:
-> 1549 fhd = iter(np.lib._datasource.open(fname, 'rbU'))
1550 else:
1551 fhd = iter(np.lib._datasource.open(fname, 'rb'))
/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.pyc in open(path, mode, destpath)
149
150 ds = DataSource(destpath)
--> 151 return ds.open(path, mode)
152
153
/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.pyc in open(self, path, mode)
499 return _file_openers[ext](found, mode=mode)
500 else:
--> 501 raise IOError("%s not found." % path)
502
503
IOError: signal_1.txt not found.
Upvotes: 0
Views: 322
Reputation: 8152
The file is not in the current directory. Only you know where it is, but maybe you meant to do something like this:
fname = os.path.join(DATADIR, 'signal_1.txt')
np.genfromtxt(fname, delimiter=',')
os.path.join()
is the best way to compose paths from strings.
Upvotes: 2