我想使用scipy.io将一个熊猫数据框保存到一个matlab .mat文件。python熊猫dataframe matlab结构使用scipy.io
我有以下:
array1 = np.array([1,2,3])
array2 = np.array(['a','b','c'])
array3 = np.array([1.01,2.02,3.03])
df = DataFrame({1:array1, 2:array2,3:array3}, index=('array1','array2','array3'))
recarray_ = df.to_records()
## Produces:
# rec.array([('array1', 1, 'a', 1.01), ('array2', 2, 'b', 2.02),
# ('array3', 3, 'c', 3.03)],
# dtype=[('index', 'O'), ('1', '<i4'), ('2', 'O'), ('3', '<f8')])
scipy.io.savemat('test_recarray_struct.mat', {'struct':df.to_records()})
在Matlab中,我希望它可以产生含有三个阵列(一个INT,一个字符,一个浮动)的结构体,但它实际上产生由含有3以上的结构结构,每个结构包含四个变量; 'index',1,'2',3.当试图选择1,'2'或3时,我得到错误'变量struct(1,1)。#不存在'。
任何人都可以解释预期的行为以及如何最好地将DataFrame保存为.mat文件吗?
做了任何一个检查这个?它工作吗? – pashute
你好pashute,我检查了我写的(在两台电脑上),它对我有用。有没有关于不适合你的解决方案?干杯,Nenad –
适合我... – nekomatic