我知道這可能是一個非常簡單且重復的問題,但我一直在閱讀 dat 檔案。
我有一個 dat 檔案,我嘗試將其讀取為 CSV。dat 檔案本身看起來是這樣的(我只貼了開頭部分,其余的和第 18 行類似):
#Occultation start (UTC): 2020-02-23 00:04:22
#Occultation stop (UTC): 2020-02-23 00:06:40
#Occultation point latitude (degN): 28.0
#Occultation point longitude (degE): -17.1
#Center of curvature (m): 11574.705 -3554.708 -13613.902
#Radius of curvature (m): 6369130.294
#Azimuth (degN): 129.789
#Undulation (m): 44.336
#Elevation (m): 0.000
#Processing method: Wave optics (CT2)
#Background data: ECMWF forecast
#Receiver data type: L1caL2p
#Navbit correction: extern
#Occultation type: Rising
#OL/CL mode: OL->CL
#Alt OL/CL (m): 11884
#alt w.r.t. EGM96 geoid|lat|lon|azimuth|ba_opt|impact_opt|refrac|dry_press|dry_temp|geopotential height|ba_raw|ba_L1|ba_L2|ba_model|snr_L1|snr_L2
0.000 -99999000.000 -99999000.000 -99999000.000 -0.99999E 08 -99999000.000 -0.99999E 08 -99999000.000 -99999000.000 -99999000.000 -0.99999E 08 -0.99999E 08 -0.99999E 08 -0.99999E 08 -99999000.000 -99999000.000
我試圖擺脫標題并通過以下方式跳過前 17 行:
newfile=[]
for line in file[17:]:
newfile.append(line.strip())
with open('newfile.csv','w') as line:
for element in newfile:
line.write(element "\n")
然后嘗試讀取 csv 檔案:
import pandas as pd
df = pd.read_csv('newfile.csv',sep=',')
print(df.head())
該檔案將顯示在 1 列和 600 行中!我怎樣才能分離列?我嘗試了不同的運算子,例如 :, ;, '' ,但沒有改變它
uj5u.com熱心網友回復:
如read_csv的 Pandas 檔案中所述,sep引數是 CSV 分隔符,即用于分隔每列的字符。在您的情況下,每列似乎由制表符或多個空格分隔。因此,應該執行以下操作(未經測驗):
import pandas as pd
df = pd.read_csv('newfile.csv',sep='\s ')
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/523230.html
標籤:Python数据框CSV
上一篇:如何編輯CSV檔案中的資料?
下一篇:使用tfilelist或tfiledelimited我如何遍歷列A、列B組合的串列并存盤在tjava中以用于tdbinput
