How Should I Use The H5py Library For Storing Time Series Data?
I have some time series data that i previously stored as hdf5 files using pytables. I recently tried storing the same with h5py lib. However, since all elements of numpy array have
Solution 1:
I'd use pandas to_hdf
dt_range = pd.date_range('2016-12-01','2016-12-10')
data = np.arange(0,20).reshape(-1,2)
df = pd.DataFrame(data,index = dt_range, columns = list('ab'), dtype = 'float')
df.index = df.index.to_julian_date()
df = df.reset_index()
with pd.HDFStore('temp.h5', 'w') as h:
df.to_hdf(h, 'temp')
pd.read_hdf('temp.h5', 'temp')
Solution 2:
When I run @piRSquared
code, and look at the file with h5py
I see:
In [4]: import h5py
In [5]: f=h5py.File('temp.h5')
In [8]: list(f.keys())
Out[8]: ['temp']
In [9]: f['temp']
Out[9]: <HDF5 group "/temp" (4 members)>
In [10]: list(f['temp'].keys())
Out[10]: ['axis0', 'axis1', 'block0_items', 'block0_values']
In [11]: f['temp']['axis0'][:]
Out[11]:
array([b'index', b'a', b'b'],
dtype='|S5')
In [12]: f['temp']['axis1'][:]
Out[12]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
In [13]: f['temp']['block0_items'][:]
Out[13]:
array([b'index', b'a', b'b'],
dtype='|S5')
In [14]: f['temp']['block0_values'][:]
Out[14]:
array([[ 2.45772350e+06, 0.00000000e+00, 1.00000000e+00],
[ 2.45772450e+06, 2.00000000e+00, 3.00000000e+00],
[ 2.45772550e+06, 4.00000000e+00, 5.00000000e+00],
[ 2.45772650e+06, 6.00000000e+00, 7.00000000e+00],
[ 2.45772750e+06, 8.00000000e+00, 9.00000000e+00],
[ 2.45772850e+06, 1.00000000e+01, 1.10000000e+01],
[ 2.45772950e+06, 1.20000000e+01, 1.30000000e+01],
[ 2.45773050e+06, 1.40000000e+01, 1.50000000e+01],
[ 2.45773150e+06, 1.60000000e+01, 1.70000000e+01],
[ 2.45773250e+06, 1.80000000e+01, 1.90000000e+01]])
So it has saved the indexing information in 3 series, and the values in another, which loads as a 2d numpy array.
That's the same kind of information that I'd expect to see from a file created by pytables
.
According to it's documentation, pd.HDFStore
is using pytables
.
Post a Comment for "How Should I Use The H5py Library For Storing Time Series Data?"