我有很多.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)
适合帮助
答案 0 :(得分:1)
由于您希望将其放在pandas数据框中,只需使用pandas.read_hdf
。
http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.read_hdf.html