简体   繁体   English

使用 Python 打开 .dat 和 .atr 文件类型

[英]Open .dat and .atr file types with Python

I'm trying to read in .dat and .atr files with Python;我正在尝试使用 Python 读取 .dat 和 .atr 文件; from Physionet, these for example .来自 Physionet,例如这些 I've tried the standard context manager opening method:我试过标准的上下文管理器打开方法:

with open("path/to/files/101.dat", "rb") as f:
  for line in f: print f

But I get uninterpretable results like D"D ?C?C?C!?C?C?C?C?C for the lines. These lines should be like 3.0000000e-003 4.9950000e+000 4.3400000e+000 (I know this from published studies with this dataset). Any ideas how I can read in this data?但是我得到了像D"D ?C?C?C!?C?C?C?C?C这样无法解释的结果。这些行应该是3.0000000e-003 4.9950000e+000 4.3400000e+000 (我知道这来自使用此数据集发表的研究)。我有什么想法可以读取这些数据吗?

You can try to open it using numpy您可以尝试使用numpy打开它

import numpy as np
myarray = np.fromfile("path/to/files/101.dat",dtype=float)

To read a .dat file use the following code-要读取 .dat 文件,请使用以下代码-

record = wfdb.rdrecord('../input/apneaecg/apnea-ecg/a01') 
wfdb.plot_wfdb(record, title='Record a01 from Physionet Apnea ECG') 
display(record.__dict__)

You need to have wfdb library installed for that.您需要为此安装 wfdb 库。 The p_signal array in the above dictionary contains the ECG values for a01 person.上述字典中的 p_signal 数组包含 a01 人的心电图值。

我知道这很旧,但这对我有用:

data = np.genfromtxt('data.dat' , dtype=None, names=True, delimiter='\t')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM