【发布时间】:2022-10-17 16:08:47
【问题描述】:
我正在尝试在 python 中导入HDF5 文件。我没有详细说明文件是如何编写的。因此,我尝试了vaex 和pandas 来打开它。如何指定我的列,以便它们被识别?
我试图检查文件的结构:
$ h5ls -v file.hdf5/DataSet
Opened "file.hdf5" with sec2 driver.
DataSet Dataset {5026/Inf}
Attribute: Species scalar
Type: 12-byte null-terminated ASCII string
Attribute: Tuning scalar
Type: 8-byte null-terminated ASCII string
Location: 1:800
Links: 1
Chunks: {1} 88 bytes
Storage: 442288 logical bytes, 442288 allocated bytes, 100.00% utilization
Type: struct {
"Scan" +0 native double
"col6" +8 native double
"col5" +16 native double
"col10" +24 native double
"col7" +32 native double
"col8" +40 native double
"col1" +48 native double
"col2" +56 native double
"col4" +64 native double
"col9" +72 native double
"col3" +80 native double
} 88 bytes
vaex
当我使用vaex 时,无法识别各个列,所有数据都以单个列DataSet 结束。
import vaex as vx
df = vx.open('file.hdf5')
df
df['DataSet']
输出如下所示:
# DataSet
0 '(0., 1.36110629e-11, 5.45816316e-09, 3.79845801...
1 '(1., 1.3613447e-11, 5.45889204e-09, 3.79879826e...
...
Expression = DataSet
Length: 5,026 dtype: [('Scan', '<f8'), ('col6', '<f8'), ('col5', '<f8'), ('col10', '<f8'), ('col7', '<f8'), ('col8', '<f8'), ('col1', '<f8'), ('col2', '<f8'), ('col4', '<f8'), ('col9', '<f8'), ('col3', '<f8')] (column)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 '(0., 1.36110629e-11, 5.45816316e-09, 3.79845801...
1 '(1., 1.3613447e-11, 5.45889204e-09, 3.79879826e...
...
有没有办法告诉vx.open 我的专栏是如何组织的?
熊猫
我尝试按照建议here 使用pandas 导入文件,但是
pd.read_hdf('file.hdf5')
结果为ValueError。
【问题讨论】: