初学Python,遇到需要将mat文件转为csv文件,看了很多博客,最后找到了解决办法,代码如下:
#方法1from pandas import Series,DataFrameimport pandas as pdimport numpy as npimport h5pydatapath = 'E:/workspacelxr/contem/data.mat'file = h5py.File(datapath,'r')file.keys()def Print(name):print(name)data = file['data'][:]dfdata = pd.DataFrame(data)datapath1 = 'E:/workspacelxr/contem/data.txt'dfdata.to_csv(datapath1,index=False)
#方法2import pandas as pdimport scipyfrom scipy import iofeatures_struct = scipy.io.loadmat('E:/workspacelxr/contem/data.mat')features = features_struct['data']dfdata = pd.DataFrame(features)datapath1 = 'E:/workspacelxr/contem/data.txt'dfdata.to_csv(datapath1, index=False)
以上这篇Python读取mat文件,并转为csv文件的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林站长站。
新闻热点
疑难解答