-
-
Save techedlaksh/9001039bf54ba9d8aec3ad7f5d8bfd08 to your computer and use it in GitHub Desktop.
import scipy.io | |
import pandas as pd | |
mat = scipy.io.loadmat('file.mat') | |
mat = {k:v for k, v in mat.items() if k[0] != '_'} | |
data = pd.DataFrame({k: pd.Series(v[0]) for k, v in mat.iteritems()}) | |
data.to_csv("example.csv") |
hello I have 980 mat files they contain ecg records. I want to convert them to a single csv. What code should I write in python?
did anyone find a proper solution for this?
hello I have 980 mat files they contain ecg records. I want to convert them to a single csv. What code should I write in python?
Hi, did you find a proper solution for this?
If yes, could you please post your solution here . thanks in advanced
import scipy.io import pandas as pd mat = scipy.io.loadmat('file.mat') mat = {k:v for k, v in mat.items() if k[0] != '_'} data = pd.DataFrame({k: pd.Series(v[0]) for k, v in mat.items()}) data.to_csv("example.csv")
This should work. use items() instead of iteritems()
Executing the above code causes the following error:
Traceback (most recent call last): File "mat2csv.py", line 6, in <module> data = pd.DataFrame({k: pd.Series(v[0]) for k, v in mat.iteritems()}) AttributeError: 'dict' object has no attribute 'iteritems'
Changed mat.iteritems() to mat.items() and then it works. (as Python 3 renamed iteritems to items)
thanks for your explanation, it is working now but this code return only single row of data what should i do to get entire data in format of dataframe , thanks in advanc.
import scipy.io import pandas as pd mat = scipy.io.loadmat('file.mat') mat = {k:v for k, v in mat.items() if k[0] != '_'} data = pd.DataFrame({k: pd.Series(v[0]) for k, v in mat.items()}) data.to_csv("example.csv")
This should work. use items() instead of iteritems()
Executing the above code causes the following error:
Traceback (most recent call last): File "mat2csv.py", line 6, in <module> data = pd.DataFrame({k: pd.Series(v[0]) for k, v in mat.iteritems()}) AttributeError: 'dict' object has no attribute 'iteritems'
Changed mat.iteritems() to mat.items() and then it works. (as Python 3 renamed iteritems to items)
That's what I said.
loadmat won't work