numpy.genfromtxt路径值
numpy.genfromtxt path value
我想用 genformtxt() 加载一个 txt 文件。 txt 文件已经在 c:.
stock=np.genfromtxt('c:012017.txt',delimiter=' ',dtype=str,skip_header=1)
C:\Anaconda3\lib\site-packages\numpy\lib\npyio.py 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)
1549 fhd = iter(np.lib._datasource.open(fname, 'rbU'))
1550 else:
-> 1551 fhd = iter(np.lib._datasource.open(fname, 'rb'))
1552 own_fhd = True
1553 else:
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in open(path, mode, destpath)
149
150 ds = DataSource(destpath)
--> 151 return ds.open(path, mode)
152
153
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in open(self, path, mode)
492
493 # NOTE: _findfile will fail on a new file opened for writing.
--> 494 found = self._findfile(path)
495 if found:
496 _fname, ext = self._splitzipext(found)
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in _findfile(self, path)
335
336 for name in filelist:
--> 337 if self.exists(name):
338 if self._isurl(name):
339 name = self._cache(name)
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in exists(self, path)
440
441 # Test local path
--> 442 if os.path.exists(path):
443 return True
444
C:\Anaconda3\lib\genericpath.py in exists(path)
17 """Test whether a path exists. Returns False for broken symbolic links"""
18 try:
---> 19 os.stat(path)
20 except OSError:
21 return False
ValueError: stat: embedded null character in path
路径似乎有误。我 100% 确定 txt 在光盘 c: 路径下。
请提供一些帮助。谢谢
您必须使用正斜杠或双反斜杠
stock=np.genfromtxt('c:/09012017.txt',delimiter=' ',dtype=str,skip_header=1)
或
stock=np.genfromtxt('c:\09012017.txt',delimiter=' ',dtype=str,skip_header=1)
如果您只使用一个反斜杠,它将被视为转义命令,这不是您想在那里做的事情。
如果只调用文件名而不调用绝对路径,则文件必须位于python
进程的工作目录下;这是启动您 python 进程的 shell 的工作目录。
我想用 genformtxt() 加载一个 txt 文件。 txt 文件已经在 c:.
stock=np.genfromtxt('c:012017.txt',delimiter=' ',dtype=str,skip_header=1)
C:\Anaconda3\lib\site-packages\numpy\lib\npyio.py 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)
1549 fhd = iter(np.lib._datasource.open(fname, 'rbU'))
1550 else:
-> 1551 fhd = iter(np.lib._datasource.open(fname, 'rb'))
1552 own_fhd = True
1553 else:
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in open(path, mode, destpath)
149
150 ds = DataSource(destpath)
--> 151 return ds.open(path, mode)
152
153
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in open(self, path, mode)
492
493 # NOTE: _findfile will fail on a new file opened for writing.
--> 494 found = self._findfile(path)
495 if found:
496 _fname, ext = self._splitzipext(found)
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in _findfile(self, path)
335
336 for name in filelist:
--> 337 if self.exists(name):
338 if self._isurl(name):
339 name = self._cache(name)
C:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in exists(self, path)
440
441 # Test local path
--> 442 if os.path.exists(path):
443 return True
444
C:\Anaconda3\lib\genericpath.py in exists(path)
17 """Test whether a path exists. Returns False for broken symbolic links"""
18 try:
---> 19 os.stat(path)
20 except OSError:
21 return False
ValueError: stat: embedded null character in path
路径似乎有误。我 100% 确定 txt 在光盘 c: 路径下。 请提供一些帮助。谢谢
您必须使用正斜杠或双反斜杠
stock=np.genfromtxt('c:/09012017.txt',delimiter=' ',dtype=str,skip_header=1)
或
stock=np.genfromtxt('c:\09012017.txt',delimiter=' ',dtype=str,skip_header=1)
如果您只使用一个反斜杠,它将被视为转义命令,这不是您想在那里做的事情。
如果只调用文件名而不调用绝对路径,则文件必须位于python
进程的工作目录下;这是启动您 python 进程的 shell 的工作目录。