我试图读取名为testfile.txt
的文本文件。 我使用NumPy函数genfromtext
,但是我得到一个Index error: Too many indices
。在Python中读取txt文件
文本文件包含数字的6列:
% Notes: 1A
% Mach Number:
% Barometric Pressure: 1036 bar
% Load using MATLAB command: data = load('filename')
% Columns: mm, p/pt, C4, C5, C4raw, C5raw
44.800000 0.781381 804.605260 1029.721933 -0.015945 -0.001723
56.800000 0.681254 699.772376 1027.182448 -0.022291 -0.001977
59.800000 0.627379 643.578986 1025.821491 -0.025692 -0.002113
62.800000 0.572096 586.082966 1024.447808 -0.029170 -0.002250
74.800000 0.440294 449.643875 1021.234840 -0.037422 -0.002571
79.800000 0.384134 391.777963 1019.900507 -0.040921 -0.002705
84.800000 0.336203 342.518031 1018.784082 -0.043898 -0.002816
96.800000 0.270190 274.847768 1017.238791 -0.047987 -0.002971
这是我的代码:
import numpy as np
table = np.genfromtxt("testfile.txt",dtype = "float",delimiter = ",",comments = "%")
mm = table[:,0]
ppt = table[:,1]
C4 = table[:,2]
C5 = table[:,3]
C4raw = table[:,4]
C5raw = table[:,5]
print ppt
更多信息:输入文件(或它的一部分)和完整的错误 –
上,则该错误发生什么行代码的? –
错误发生在行mm = table [:,0]处,文本文件由六列数字组成。我添加了文本文件的图像 – aeengineer