簡體   English   中英

如何使用Python檢索HDF5文件

[英]How to use Python to retrieve HDF5 files

我有很多.dat格式的文件,這些文件的內部結構被構造為hdf5結構,它具有不同的數據組。 現在,我需要一些如何以表的形式檢索內部數據以查看這些數據。 我試圖用h5py讀取文件並將其放入pandas數據框,但不幸的是出現了一些錯誤,有人可以為我提供一些示例來解決此問題嗎?

import h5py
import pandas as pa

with h5py.File("01.dat") as f:
    rdata = f.value[-1]

print rdata

This method also tried, but same error.

with h5py.File('01.dat','r') as hf:
    print('List of arrays in this file: \n', hf.keys())

下面的錯誤看起來像無法讀取01.dat文件。

C:\Anaconda2\python.exe C:/Users/FLU2/PycharmProjects/Dask/Dask.py
Traceback (most recent call last):
  File "C:/Users/FLU2/PycharmProjects/Dask/Dask.py", line 4, in <module>
    with h5py.File("01.dat") as f:
  File "C:\Anaconda2\lib\site-packages\h5py\_hl\files.py", line 260, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "C:\Anaconda2\lib\site-packages\h5py\_hl\files.py", line 114, in make_fid
    fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (C:\aroot\work\h5py\_objects.c:2584)
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (C:\aroot\work\h5py\_objects.c:2543)
  File "h5py\h5f.pyx", line 96, in h5py.h5f.create (C:\aroot\work\h5py\h5f.c:1994)
IOError: Unable to create file (Unable to open file: name = '01.dat', errno = 17, error message = 'file exists', flags = 15, o_flags = 502)

適當的幫助

通過下面的內部數據結構,有元數據,結果和時間序列,在時間序列部分有30個不同的組。 在此處輸入圖片說明

由於您要將其放在pandas數據pandas.read_hdf ,因此請使用pandas.read_hdf

http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.read_hdf.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM