I am trying to save the pandas framework to a matlab.mat file using scipy.io.
I have the following:
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()
#
# 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()})
In Matlab, I would expect this to create a structure containing three arrays (one int, one char, one float), but in fact it creates a structure containing 3 more structures, each of which contains four variables; 'index', 1, '2', 3. When I try to select 1, '2' or 3, I get the error message 'Variable struct (1, 1). # does not exist.'
Can someone explain the expected behavior and what is the best way to save DataFrames in .mat files?