我有很多.dat格式的文件,文件的内部结构是作为hdf5结构构造的,它有不同的数据组。现在,我需要一些如何检索内部数据作为一个表来查看这些数据。我试着用h5py来读取这个文件并把它放到熊猫的数据中,但是不幸的是,有人能给我提供一些例子来解决这个问题吗?
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个不同的组。
发布于 2016-03-07 21:02:12
既然你想把它放进熊猫的资料里,就用pandas.read_hdf
吧。
hdf.html
https://stackoverflow.com/questions/35853639
复制相似问题