我正在尝试读取文件,特别是,我想阅读它的特定列。问题是标题有四列,而数据有两列。我怎么能用Python做到这一点?我正在尝试阅读的文件看起来像这样
96564 330 11 1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1.276179694473037E+00 1.666387732294628E+00
-1.7567416009136452E-004 -2.1164129099324222E-003 2.1490310576924058E-005 -2.7620298845456630 -1.8938557128664963 8.1451380842752732E-002 5.6798992969198242E-003
-2.4287971047070860E-005 -2.3609881614543712E-003 3.1144023010759590E-005 4.0745088882476184 0.33917759997860736 1.4630230584405567E-002 1.3515126501174172E-003
5.1771204588632223E-004 -2.3859807510696008E-003 4.5398813079852952E-005 0.45840350786923445 2.6436923397475449 3.1001309161949490E-002 1.3304268623415794E-003
2.0168729283814068E-003 -2.8511940463213253E-003 6.1138543197632175E-005 2.8865136613288249 2.2963200558859995 3.3124888426326403E-002 1.2587884928308795E-003
-2.1486254552195442E-004 -2.1629086122666023E-003 1.3836748439773666E-005 7.7251215411289289 1.7052985468843680 -0.78855585945347717 6.8568153674527599E-004
5.0931650983650221E-006 -2.3443067492165833E-003 2.5411108135731121E-005 0.23718439736076949 5.8967883591361314 0.48056164762398068 7.2087010119962060E-004
1.9187225151669921E-003 -2.1025090182238706E-003 8.8987477328659638E-005 -0.25318942890334173 1.9430755960869355 4.6912070943073196E-002 1.4532354957884940E-003
-3.7740008788295651E-004 -2.6810238020915111E-003 3.3177567534301046E-005 3.9967795229052840 0.41588955059533705 -3.3938217242456201E-002 7.8802206461770473E-004
8.8238186001925103E-004 -5.0404770964643329E-004 5.9745726301358809E-005 -2.5028283387987362 1.2005940373166184 -0.30136573399772792 7.4708585346873338E-004
-1.8595757572406899E-003 -2.7475038056757380E-003 2.5570423015501202E-005 -5.4697141814638035E-002 -2.6754750580122764 -6.6391158401522363E-002 1.0234052787242941E-003
-3.5376590824452540E-004 -4.1009265163613976E-003 -8.1420707166233811E-006 1.9466623872113207 -0.10603400063515293 -0.29897526568706323 1.6929128358203331E-004
答案 0 :(得分:0)
with open('file1.txt') as f:
for line in f:
arr = line.split()
if len(arr) == 4: # 4 column so this is header
continue
# do whatever after if statement