【问题标题】:Extract data into numpy arrays from hdf5 file从 hdf5 文件中提取数据到 numpy 数组中
【发布时间】:2021-03-23 20:36:09
【问题描述】:

尽管围绕此任务找到了一些资源,但我无法从 hdf5 文件中提取数据(对于我正在学习的 Datacamp 课程)。

我想在我的本地系统上处理这些示例。

这就是我所拥有的:

import h5py
import numpy as np
import pandas as pd

filename = "e:\\python\\datacamp\\time_series_with_python\\machine_learning_for_time_series_data_in_python\\audio_munged.hdf5"
'''
data = pd.read_hdf(filename, key)
data = pd.read_hdf(filename, 'h5io')
print(data)
# Reading the file
'''

f = h5py.File(filename, 'r')

# Studying the structure of the file by printing what HDF5 groups are present

for key in f.keys():
    print(key)  # Names of the groups in HDF5 file.

    # Extracting the data

    # Get the HDF5 group
    group = f[key]

    # Checkout what keys are inside that group.
    for gkey in group.keys():
        print(gkey)
    # key_data = group['key_data'].value   <-- This generates an error

我明白了:

h5io
key_data
key_meta
key_sfreq

Traceback (most recent call last):
  File "C:/Users/Mark/PycharmProjects/main/main.py", line 27, in <module>
    key_data = group['key_data'].value
AttributeError: 'Group' object has no attribute 'value'

问题 #1:如何将 'key_data'、key_meta' 和 'key_sfreq' 中的值提取到单独的 numpy 数组中?

问题 #2:我尝试简单地将 hdf5 文件拉入 pandas(上面的代码),但我不知道什么是正确的 'key' 参数的值应该是。我试过 h5io 但这不正确。然后我尝试了其他三个(key_),所有这些都失败了。

【问题讨论】:

  • 试试group['key_data']group['key_data'].values()
  • 选项 1 产生: 选项 2 产生:ValuesViewHDF5()

标签: python-3.x pandas numpy h5py


【解决方案1】:

我在这里找到了我要找的东西:

https://stackoverflow.com/questions/34330283/how-to-differentiate-between-hdf5-datasets-and-groups-with-h5py

我没有深入。用户“Yas”发布的代码向我展示了如何获取这些值。

【讨论】:

    猜你喜欢
    • 2016-02-10
    • 2017-09-23
    • 1970-01-01
    • 2014-12-21
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 2018-03-25
    相关资源
    最近更新 更多