【问题标题】:HDF5 dataset from MATLAB to Pandas DataFrame in Python从 MATLAB 到 Python 中的 Pandas DataFrame 的 HDF5 数据集
【发布时间】:2017-10-27 21:04:03
【问题描述】:

我有带有 HDF5 数据的 .mat 文件,我想将其加载到 Python (Pandas DataFrame) 中。我可以加载文件:

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

这是一个 HDF5 数据集:

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

如果我用 Pandas 阅读它:

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

我收到以下错误:

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

如何将其转换为 Pandas DataFrame?

【问题讨论】:

    标签: python matlab pandas hdf5 data-science-experience


    【解决方案1】:

    AFAIK 你无法使用 Pandas 方法读取 HDF5 文件,这些文件不是使用 Pandas 编写的。

    您可以使用以下方法之一阅读它们:

    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

    【讨论】:

    • 我想知道它无法完成是我必须接受的答案。我可能会走 numpy 数组路线。感谢您的信息。
    【解决方案2】:

    在第一个示例中,您的文件是 "file.mat",在第二个示例中是 "data.mat"

    【讨论】:

      猜你喜欢
      • 2014-03-04
      • 2016-05-12
      • 2013-02-26
      • 2016-11-06
      • 2018-02-22
      • 2016-10-27
      • 1970-01-01
      • 2016-09-08
      • 2023-03-17
      相关资源
      最近更新 更多