techedlaksh / mat_to_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import scipy . io |
import pandas as pd |
mat = scipy . io . loadmat ( ‘file.mat’ ) |
mat = |
data = pd . DataFrame (< k : pd . Series ( v [ 0 ]) for k , v in mat . iteritems ()>) |
data . to_csv ( «example.csv» ) |
import scipy.io import pandas as pd mat = scipy.io.loadmat('file.mat') mat = data = pd.DataFrame() 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 data = pd.DataFrame() AttributeError: ‘dict’ object has no attribute ‘iteritems’
Changed mat.iteritems() to mat.items() and then it works. (as Python 3 renamed iteritems to items)
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?
Exception Traceback (most recent call last) in 4 mat = scipy.io.loadmat('S1.mat') 5 mat = ----> 6 data = pd.DataFrame() 7 data.to_csv("example.csv") in (.0) 4 mat = scipy.io.loadmat('S1.mat') 5 mat = ----> 6 data = pd.DataFrame() 7 data.to_csv("example.csv") /opt/anaconda3/lib/python3.8/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath) 325 data = data.copy() 326 else: --> 327 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True) 328 329 data = SingleBlockManager.from_array(data, index) /opt/anaconda3/lib/python3.8/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure) 494 elif subarr.ndim > 1: 495 if isinstance(data, np.ndarray): --> 496 raise Exception("Data must be 1-dimensional") 497 else: 498 subarr = com.asarray_tuplesafe(data, dtype=dtype) Exception: Data must be 1-dimensional
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?
open a new csv file and then
- convertt one mat file to csv, write in the previously opened csv shift columns as per your mat file
- loop
Hello when i am trying to run this code the following error is raised because of line 6:
data = pd.DataFrame()
File «C:\python\lib\site-packages\pandas\core\series.py», line 269, in init
raise ValueError(
ValueError: Cannot construct a Series from an ndarray with compound dtype. Use DataFrame instead.
How do i do this ?
If you are still not able to solve the problem,
Check this code,
https://www.kaggle.com/vinayak123tyagi/mat-to-csv-code
(might not be perfect one)
This might be helpful for you.
In my opinion, you have to loop to dic items and itter throw them.
To save extracted data in csv format you have to make DataFrame( which currently you are getting as an error)
Traceback (most recent call last): File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 11, in mat = scipy.io.loadmat(f) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 225, in loadmat MR, _ = mat_reader_factory(f, **kwargs) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 74, in mat_reader_factory mjv, mnv = get_matfile_version(byte_stream) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\miobase.py", line 212, in get_matfile_version mopt_bytes = fileobj.read(4) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 204: character maps to
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?
Yes iPhone’umdan gönderildi Jay Gupta ***@***.***> şunları yazdı (4 Oca 2023 22:45): @jaygupta-2k commented on this gist.
techedlaksh / mat_to_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import scipy . io |
import pandas as pd |
mat = scipy . io . loadmat ( ‘file.mat’ ) |
mat = |
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?
open a new csv file and then
- convertt one mat file to csv, write in the previously opened csv shift columns as per your mat file
- loop
Hello when i am trying to run this code the following error is raised because of line 6:
data = pd.DataFrame()
File «C:\python\lib\site-packages\pandas\core\series.py», line 269, in init
raise ValueError(
ValueError: Cannot construct a Series from an ndarray with compound dtype. Use DataFrame instead.
How do i do this ?
If you are still not able to solve the problem,
Check this code,
https://www.kaggle.com/vinayak123tyagi/mat-to-csv-code
(might not be perfect one)
This might be helpful for you.
In my opinion, you have to loop to dic items and itter throw them.
To save extracted data in csv format you have to make DataFrame( which currently you are getting as an error)
Traceback (most recent call last): File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 11, in mat = scipy.io.loadmat(f) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 225, in loadmat MR, _ = mat_reader_factory(f, **kwargs) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 74, in mat_reader_factory mjv, mnv = get_matfile_version(byte_stream) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\miobase.py", line 212, in get_matfile_version mopt_bytes = fileobj.read(4) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 204: character maps to
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?
Yes iPhone’umdan gönderildi Jay Gupta ***@***.***> şunları yazdı (4 Oca 2023 22:45): @jaygupta-2k commented on this gist.
techedlaksh / mat_to_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import scipy . io |
import pandas as pd |
mat = scipy . io . loadmat ( ‘file.mat’ ) |
mat = |
data = pd . DataFrame (< k : pd . Series ( v [ 0 ]) for k , v in mat . iteritems ()>) |
data . to_csv ( «example.csv» ) |
import scipy.io import pandas as pd mat = scipy.io.loadmat('file.mat') mat = data = pd.DataFrame() 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 data = pd.DataFrame() AttributeError: ‘dict’ object has no attribute ‘iteritems’
Changed mat.iteritems() to mat.items() and then it works. (as Python 3 renamed iteritems to items)
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?
Exception Traceback (most recent call last) in 4 mat = scipy.io.loadmat('S1.mat') 5 mat = ----> 6 data = pd.DataFrame() 7 data.to_csv("example.csv") in (.0) 4 mat = scipy.io.loadmat('S1.mat') 5 mat = ----> 6 data = pd.DataFrame() 7 data.to_csv("example.csv") /opt/anaconda3/lib/python3.8/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath) 325 data = data.copy() 326 else: --> 327 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True) 328 329 data = SingleBlockManager.from_array(data, index) /opt/anaconda3/lib/python3.8/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure) 494 elif subarr.ndim > 1: 495 if isinstance(data, np.ndarray): --> 496 raise Exception("Data must be 1-dimensional") 497 else: 498 subarr = com.asarray_tuplesafe(data, dtype=dtype) Exception: Data must be 1-dimensional
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?
open a new csv file and then
- convertt one mat file to csv, write in the previously opened csv shift columns as per your mat file
- loop
Hello when i am trying to run this code the following error is raised because of line 6:
data = pd.DataFrame()
File «C:\python\lib\site-packages\pandas\core\series.py», line 269, in init
raise ValueError(
ValueError: Cannot construct a Series from an ndarray with compound dtype. Use DataFrame instead.
How do i do this ?
If you are still not able to solve the problem,
Check this code,
https://www.kaggle.com/vinayak123tyagi/mat-to-csv-code
(might not be perfect one)
This might be helpful for you.
In my opinion, you have to loop to dic items and itter throw them.
To save extracted data in csv format you have to make DataFrame( which currently you are getting as an error)
Traceback (most recent call last): File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 11, in mat = scipy.io.loadmat(f) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 225, in loadmat MR, _ = mat_reader_factory(f, **kwargs) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\mio.py", line 74, in mat_reader_factory mjv, mnv = get_matfile_version(byte_stream) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\site-packages\scipy\io\matlab\miobase.py", line 212, in get_matfile_version mopt_bytes = fileobj.read(4) File "C:\Users\mirko\anaconda3\envs\sixSigma\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 204: character maps to
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?
Yes iPhone’umdan gönderildi Jay Gupta ***@***.***> şunları yazdı (4 Oca 2023 22:45): @jaygupta-2k commented on this gist.