Reputation: 167
I have a lot of .dat format files the files internal structure is construct as hdf5 structure it have different groups of data. Now I need some how to retrieve the internal data as a table to view those datas. i tried to used h5py to read the file and put it to pandas dataframe, but unfortunately have some error does anyone can provided some example for me to solve this problem?
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())
The error below, looks like unable to read the 01.dat file.
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)
Appropriate for the help
By the way the internal data structure below, have meta data , result, and time series ,during the time series part it have 30 different groups.
Upvotes: 0
Views: 1087
Reputation: 719
Since you want to put it in a pandas dataframe, just use pandas.read_hdf
.
http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.read_hdf.html
Upvotes: 1