每秒的值都是nan
这样,这可能是一些分隔符。此外,文件中的值是列优先的。以下脚本读取数据,丢弃 NaN 条目,将数组操作为正确的形状,并输出与您发布的文件相同的 CSV 文件:
import csv
import numpy as np
# Pull in all the raw data.
with open('TEMPO3.2F-0215_s00116.dat', 'rb') as f:
raw = np.fromfile(f, np.float64)
# Throw away the nan entries.
raw = raw[1::2]
# Check its a multiple of six so we can reshape it.
if raw.size % 6:
raise ValueError("Data size not multiple of six.")
# Reshape and take the transpose to manipulate it into the
# same shape as your CSV. The conversion to integer is also
# so the CSV file is the same.
data = raw.reshape((6, raw.size/6)).T.astype('int')
# Dump it out to a CSV.
with open('test.csv', 'w') as f:
w = csv.writer(f)
w.writerows(data)
编辑:更新版本与jorgeca建议的更改:
import csv
import numpy as np
# Pull in all the raw data.
raw = np.fromfile('TEMPO3.2F-0215_s00116.dat', np.float64)
# Throw away the nan entries.
raw = raw[1::2]
# Reshape and take the transpose to manipulate it into the
# same shape as your CSV. The conversion to integer is also
# so the CSV file is the same.
data = raw.reshape((6, -1)).T.astype('int')
# Dump it out to a CSV.
with open('test.csv', 'w') as f:
w = csv.writer(f)
w.writerows(data)