-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.py
27 lines (22 loc) · 1014 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Code to convert all .dat files (ECG signals) in a folder to CSV format
@author: Abhishek Patil
"""
import wfdb #WaveForm-Database package. A library of tools for reading, writing, and processing WFDB signals and annotations.
import pandas as pd
import numpy as np
import glob
dat_files=glob.glob('*.dat') #Get list of all .dat files in the current folder
df=pd.DataFrame(data=dat_files)
df.to_csv("files_list.csv",index=False,header=None) #Write the list to a CSV file
files=pd.read_csv("files_list.csv",header=None)
for i in range(1,len(files)+1):
recordname=str(files.iloc[[i]])
print(recordname[:-4])
recordname_new=recordname[-7:-4] #Extracting just the filename part (will differ from database to database)
record = wfdb.rdsamp(recordname_new) # rdsamp() returns the signal as a numpy array
record=np.asarray(record[0])
path=recordname_new+".csv"
np.savetxt(path,record,delimiter=",") #Writing the CSV for each record
print("Files done: %s/%s"% (i,len(files)))
print("\nAll files done!")