我試圖讀取名爲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