How to read data from .mat file and export to CSV in python?

我怕爱的太早我们不能终老 提交于 2020-06-29 04:10:12

问题


I know there are many answers but none of them solved my problem.

I have a .mat file and i want to export it's data to Csv.

The code that i tried:

import h5py
arrays={}
   f=h5py.File('datafile.mat')
   for k,v in f.items():
       arrays[k]=np.array(v)

Which got me output in dictionary

 {'#refs#': array(['0', '00', '00b', ..., 'zzj', 'zzk', 'zzl'], dtype='<U3'),
  'MasterOperations': array(['Code', 'ID', 'Label'], dtype='<U5'),
  'Operations': array(['CodeString', 'ID', 'Keywords', 'MasterID', 'Name'], dtype='<U10'),
  'TS_CalcTime': array([[7.1010e-03, 2.5500e-04, 2.5300e-04, ..., 1.0800e-04, 9.5000e-05,
    9.4000e-05],
   [1.2238e-02, 8.0800e-04, 2.3500e-04, ..., 1.1400e-04, 9.6000e-05,
     9.3000e-05],

-------and so on

and if i tried converting it into Dataframe then

ValueError: arrays must all be same length

I want export whole data into csv file without losing aur excluding any part.

Thanks

来源:https://stackoverflow.com/questions/62348024/how-to-read-data-from-mat-file-and-export-to-csv-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!