无法从txt文件导入数据

时间:2018-01-10 10:43:33

标签: python numpy

这是我的代码

import numpy as np #Data manupulation import and export data = np.genfromtxt('data_file.txt', delimiter=',') data[0:4]

以下是错误消息。

C:\Users\udari\AppData\Local\Programs\Python\Python36\python.exe "E:/My Works/PythonWorks/myScript.py"
Traceback (most recent call last):
  File "E:/My Works/PythonWorks/myScript.py", line 4, in <module>
    data = np.genfromtxt('data_file.txt', delimiter=',')
  File "C:\Users\udari\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\lib\npyio.py", line 2014, in genfromtxt
    raise ValueError(errmsg)
ValueError: Some errors were detected !

 - Line #2 (got 1 columns instead of 2)
    Line #3 (got 1 columns instead of 2)
    Line #4 (got 1 columns instead of 2)
    Line #5 (got 1 columns instead of 2)
    Line #6 (got 1 columns instead of 2)
    Line #7 (got 1 columns instead of 2)
    Line #8 (got 3 columns instead of 2)
    Line #9 (got 3 columns instead of 2)
    Line #10 (got 5 columns instead of 2)
    Line #11 (got 1 columns instead of 2)
    Line #12 (got 1 columns instead of 2)
    Line #13 (got 3 columns instead of 2)
    Line #14 (got 3 columns instead of 2)
    Line #15 (got 4 columns instead of 2)
    Line #16 (got 3 columns instead of 2)
    Line #17 (got 1 columns instead of 2)
    Line #18 (got 1 columns instead of 2)
    Line #19 (got 1 columns instead of 2)
    Line #21 (got 1 columns instead of 2)
    Line #22 (got 1 columns instead of 2)
    Line #23 (got 1 columns instead of 2)
    Line #24 (got 1 columns instead of 2)
    Line #26 (got 1 columns instead of 2)
    Line #27 (got 7 columns instead of 2)
    Line #28 (got 4 columns instead of 2)
    Line #31 (got 9 columns instead of 2)
    Line #32 (got 1 columns instead of 2)
    Line #33 (got 3 columns instead of 2)
    Line #35 (got 1 columns instead of 2)
    Line #36 (got 1 columns instead of 2)
    Line #37 (got 1 columns instead of 2)
    Line #38 (got 1 columns instead of 2)
    Line #39 (got 1 columns instead of 2)
    Line #40 (got 1 columns instead of 2)
    Line #41 (got 1 columns instead of 2)
    Line #42 (got 1 columns instead of 2)
    Line #43 (got 1 columns instead of 2)
    Line #44 (got 1 columns instead of 2)
    Line #45 (got 1 columns instead of 2)
    Line #46 (got 1 columns instead of 2)
    Line #47 (got 1 columns instead of 2)
    Line #48 (got 1 columns instead of 2)
    Line #49 (got 1 columns instead of 2)
    Line #50 (got 1 columns instead of 2)
    Line #51 (got 1 columns instead of 2)
    Line #52 (got 1 columns instead of 2)
    Line #53 (got 3 columns instead of 2)
    Line #54 (got 1 columns instead of 2)
    Line #55 (got 1 columns instead of 2)
    Line #56 (got 1 columns instead of 2)
    Line #57 (got 3 columns instead of 2)
    Line #58 (got 1 columns instead of 2)
    Line #59 (got 1 columns instead of 2)
    Line #60 (got 1 columns instead of 2)
    Line #61 (got 1 columns instead of 2)
    Line #62 (got 1 columns instead of 2)
    Line #63 (got 1 columns instead of 2)
    Line #64 (got 1 columns instead of 2)
    Line #65 (got 1 columns instead of 2)
    Line #66 (got 1 columns instead of 2)
    Line #67 (got 3 columns instead of 2)
    Line #68 (got 1 columns instead of 2)
    Line #69 (got 1 columns instead of 2)
    Line #71 (got 1 columns instead of 2)
    Line #72 (got 3 columns instead of 2)
    Line #73 (got 1 columns instead of 2)
    Line #74 (got 1 columns instead of 2)
    Line #76 (got 1 columns instead of 2)
    Line #77 (got 3 columns instead of 2)
    Line #78 (got 1 columns instead of 2)
    Line #79 (got 1 columns instead of 2)
    Line #80 (got 1 columns instead of 2)
    Line #81 (got 1 columns instead of 2)
    Line #82 (got 1 columns instead of 2)
    Line #83 (got 1 columns instead of 2)
    Line #84 (got 1 columns instead of 2)
    Line #85 (got 1 columns instead of 2)
    Line #86 (got 1 columns instead of 2)
    Line #87 (got 1 columns instead of 2)
    Line #88 (got 1 columns instead of 2)
    Line #89 (got 1 columns instead of 2)
    Line #90 (got 1 columns instead of 2)
    Line #91 (got 3 columns instead of 2)
    Line #92 (got 1 columns instead of 2)
    Line #93 (got 3 columns instead of 2)
    Line #94 (got 1 columns instead of 2)
    Line #95 (got 1 columns instead of 2)
    Line #97 (got 1 columns instead of 2)
    Line #98 (got 3 columns instead of 2)
    Line #100 (got 3 columns instead of 2)
    Line #102 (got 3 columns instead of 2)
    Line #104 (got 1 columns instead of 2)
    Line #105 (got 17 columns instead of 2)
    Line #106 (got 17 columns instead of 2)
    Line #107 (got 17 columns instead of 2)
    Line #108 (got 17 columns instead of 2)
    Line #109 (got 17 columns instead of 2)
    Line #110 (got 17 columns instead of 2)
    Line #111 (got 17 columns instead of 2)
    Line #112 (got 17 columns instead of 2)
    Line #113 (got 17 columns instead of 2)
    Line #114 (got 17 columns instead of 2)
    Line #115 (got 17 columns instead of 2)
    Line #116 (got 17 columns instead of 2)
    Line #117 (got 17 columns instead of 2)
    Line #118 (got 17 columns instead of 2)
    Line #119 (got 17 columns instead of 2)
    Line #120 (got 17 columns instead of 2)
    Line #121 (got 17 columns instead of 2)
    Line #122 (got 17 columns instead of 2)
    Line #123 (got 17 columns instead of 2)
    Line #124 (got 17 columns instead of 2)
    Line #125 (got 17 columns instead of 2)
    Line #126 (got 17 columns instead of 2)
    Line #127 (got 17 columns instead of 2)
    Line #128 (got 17 columns instead of 2)
    Line #129 (got 17 columns instead of 2)
    Line #130 (got 17 columns instead of 2)
    Line #131 (got 17 columns instead of 2)
    Line #132 (got 17 columns instead of 2)
    Line #133 (got 17 columns instead of 2)
    Line #134 (got 17 columns instead of 2)
    Line #135 (got 17 columns instead of 2)
    Line #136 (got 17 columns instead of 2)
    Line #137 (got 17 columns instead of 2)
    Line #138 (got 17 columns instead of 2)
    Line #139 (got 17 columns instead of 2)
    Line #140 (got 17 columns instead of 2)
    Line #141 (got 17 columns instead of 2)
    Line #142 (got 17 columns instead of 2)
    Line #143 (got 17 columns instead of 2)
    Line #144 (got 17 columns instead of 2)
    Line #145 (got 17 columns instead of 2)
    Line #146 (got 17 columns instead of 2)
    Line #147 (got 17 columns instead of 2)
    Line #148 (got 17 columns instead of 2)
    Line #149 (got 17 columns instead of 2)
    Line #150 (got 17 columns instead of 2)
    Line #151 (got 17 columns instead of 2)
    Line #152 (got 17 columns instead of 2)
    Line #153 (got 17 columns instead of 2)
    Line #154 (got 17 columns instead of 2)
    Line #155 (got 17 columns instead of 2)
    Line #156 (got 17 columns instead of 2)
    Line #157 (got 17 columns instead of 2)
    Line #158 (got 17 columns instead of 2)
    Line #159 (got 17 columns instead of 2)
    Line #160 (got 17 columns instead of 2)
    Line #161 (got 17 columns instead of 2)
    Line #162 (got 1 columns instead of 2)
    Line #163 (got 1 columns instead of 2)
    Line #164 (got 1 columns instead of 2)

Process finished with exit code 1

1 个答案:

答案 0 :(得分:0)

从您在评论中添加的文本文件示例中,很明显您的文件是ARFF filenumpy.genfromtxt无法读取此类文件。相反,您可以使用scipy.io.arff.loadarff。但请注意,SciPy ARFF阅读器无法理解完整的ARFF文件格式。如果您的文件使用未在SciPy阅读器中实现的功能,它将无法工作。

在python中读取ARFF文件的其他选项包括liac-arffarff