操作系统错误:未找到“.txt”

Posted

技术标签:

【中文标题】操作系统错误:未找到“.txt”【英文标题】:OSError: ".txt" not found 【发布时间】:2019-02-14 19:47:11 【问题描述】:

我正在尝试使用这个简单的代码从 .CSV 文件中读取数据,将其拆分并保存为多个 .txt 文件,然后使用以下代码加载以进行测试:

import pandas as pd
import numpy as np


data = pd.read_csv("C:/Users/m/Desktop/python/IRB3MAIZ9936-a.csv") #, sep="\s")

del data['DATE']

matx = np.array(data.values, dtype= int)
rows,cols = matx.shape

count = 1
j = 25
for i in range(rows%25):
    matxx = matx[i%25:j , :] 
    j += 25
    np.savetxt(f' datacount.txt ' , matxx, fmt='%d')
    count +=1
nn = np.loadtxt('data10.txt' , dtype = int)
print()

但我收到此错误消息:

Traceback (most recent call last):
  File "C:\Users\m\Desktop\python\read_csv.py", line 19, in <module>
    nn = np.loadtxt('data10.txt' , dtype = int)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 926, in loadtxt
    fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\_datasource.py", line 262, in open
    return ds.open(path, mode, encoding=encoding, newline=newline)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\_datasource.py", line 618, in open
    raise IOError("%s not found." % path)
OSError: data10.txt not found.
[Finished in 2.0s with exit code 1]
[shell_cmd: python -u "C:\Users\m\Desktop\python\read_csv.py"]
[dir: C:\Users\m\Desktop\python]
[path: C:\ProgramData\Anaconda3;C:\ProgramData\Anaconda3\Library\mingw-w64\bin;C:\ProgramData\Anaconda3\Library\usr\bin;C:\ProgramData\Anaconda3\Library\bin;C:\ProgramData\Anaconda3\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\mingw64\bin;D:\cmake-3.11.3-win64-x64\cmake-3.11.3-win64-x64\bin;C:\opencv\build\install\x64\mingw\bin;C:\Program Files\nodejs\;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Users\m\AppData\Local\Microsoft\WindowsApps;C:\Users\m\AppData\Roaming\npm;C:\Users\m\AppData\Local\Programs\Microsoft VS Code\bin]

问题是什么,我该如何解决?

【问题讨论】:

你的目录中是否有一个名为data10.txt的文件? 【参考方案1】:

您应该从您保存的文件名中删除前导空格和尾随空格:

变化:

np.savetxt(f' datacount.txt ' , matxx, fmt='%d')

到:

np.savetxt(f'datacount.txt' , matxx, fmt='%d')

【讨论】:

以上是关于操作系统错误:未找到“.txt”的主要内容,如果未能解决你的问题,请参考以下文章

系统错误 - “代码无法继续,因为未找到 .dll。”

错误 C3861:“系统”:未找到标识符

Netgen.exe - 未找到系统错误 python35.dll

试图在我的系统中安装猫鼬给出错误 404 未找到 mongoose@latest

Spotify Web SDK 错误“EMEError:未找到支持的密钥系统”

JFFS2 文件系统立即损坏(魔术位掩码 0x1985 未找到错误)