2

I have a problem loading specific Matlab file into pandas data frame (data). Basically, it is a multidimensional array consisting of 2x4 arrays and then either 3 or 4 columns. I searched through and found this Convert mat file to pandas dataframe, matlab data file to pandas DataFrame but neither works for me. Here is what I am using. Thit creates a pandas for one of the nests. I would like to have a column which will tell me where I am, ie first column tells if it is all_params[0] or all_params[1], second distinguishes the next level for each of those etc.

import numpy as np
import scipy.io as sio

all_params = sio.loadmat(path+'all_params')
all_params = all_params['all_params']
pd.DataFrame(all_params[0][0][:],  columns=['par1', 'par2', 'par3'])

It must be simple, I'm just not able to figure it out. Or is there a way how to do it directly using scipy or another loading tool?

Thanks

My Work
  • 810
  • 1
  • 4
  • 25
  • 1
    Do you mind to provide a [mcve](/help/mcve)? – rpanai Jan 02 '20 at 13:13
  • Recent versions of MATLAB write HDF5 instead of the old MAT format. loadmat can no longer read it: https://stackoverflow.com/questions/874461/read-mat-files-in-python – Daniel Jan 02 '20 at 13:27
  • The matlab mat file is accessible through the "data" link, should be available for download, if not, let me know. The code I use is there, the expected outcome I do not have in any other better form than described. I can try to describe better as well, let me know what exactly would help – My Work Jan 02 '20 at 13:35
  • My initial guess was wrong, the mat file is "old enough" to be processed with loadmat from scipy. What error do you get? – Daniel Jan 02 '20 at 13:57
  • No error, just how to load it directly to pandas so that it has the structure as I write. Or in general how to load multidimensional array in pandas because I have not found anything. The best I found I quote but it does not deal with a general case and I failed to adapt it. – My Work Jan 02 '20 at 17:24

0 Answers0