2

I have .mat files with HDF5 data and I want to load it into Python (Pandas DataFrame). I can load the file:

f2 = h5py.File("file.mat")
f2['data']

which is an HDF5 dataset:

<HDF5 dataset "data": shape (9999999, 32), type "<f8">

If I read it with Pandas:

g = pd.read_hdf("file.mat",'data')

I get the following error:

cannot create a storer if the object is not existing nor a value are passed

How do I convert this to a Pandas DataFrame?

Ross Lewis
  • 755
  • 2
  • 7
  • 17

2 Answers2

1

AFAIK you can't read HDF5 files using Pandas methods, that have NOT been written using Pandas.

You can read them using one of the following approaches:

read matlab v7.3 file into python list of numpy arrays via h5py

Reading ALL variables in a .mat file with python h5py

http://poquitopicante.blogspot.de/2014/05/loading-matlab-mat-file-into-pandas.html

Read .mat files in Python

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • I suppose knowing it can't be done is the answer I'll have to settle for. I'll probably go the numpy array route. Thanks for the info. – Ross Lewis May 26 '17 at 23:14
0

In the first example your file is "file.mat" and in the second "data.mat"

yar
  • 1,855
  • 13
  • 26