我试图写一些数据,我从一个excel文件提取到一个'。垫的文件。到目前为止,我已经将提取的数据转换为数组,并在写入.mat文件之前将该数组转换为字典。虽然到数组和字典的转换看起来很好,但当我创建并写入.mat文件时,数据似乎损坏了。下面是我的代码:
import pandas as pd
file_location = '/Users/manmohidake/GoogleDrive/Post_doc/Trial_analysis/1_IndoorOutdoor.xlsx'
mydata = pd.read_excel(file_location,na_values = "Missing", sheet_name='Sheet1', skiprows = 1, usecols="F,K,Q")
import numpy
#Convert data to array
array = mydata.to_numpy()
import scipy.io
import os
destination_folder_path = '/Users/manmohidake/Google Drive/Post_doc/Trial_analysis/'
scipy.io.savemat(os.path.join(destination_folder_path,'trial1.mat'), {'array':array})
我真的不知道哪里出了问题。当我打开。mat文件时,它。看起来像这样 Matlab文件
In [1]: from scipy import io
In [2]: arr = np.arange(12).reshape(4,3)
In [3]: io.savemat('test.mat',{'array':arr})
In [4]: io.loadmat('test.mat')
Out[4]:
{'__header__': b'MATLAB 5.0 MAT-file Platform: posix, Created on: Mon Sep 20 11:36:48 2021',
'__version__': '1.0',
'__globals__': [],
'array': array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])}
在八度
>> cd mypy
>> load test.mat
>> array
array =
0 1 2
3 4 5
6 7 8
9 10 11