I would like to add more and more data to the HDF5 file as the data comes in. I tried the following: First create a dataset with first array and then try to add one more value to the h5 file by resizing it.
import os
import h5py
import numpy as np
x = np.array([1, 2, 3, 4, 5, 6, 9, 8, 87, 2, 3, 5, 12, 14, 16]).astype(int)
y = 9
path = "out.h5"
with h5py.File(path, "a") as f:
dset = f.create_dataset("somedata", data=x, maxshape=(None,))
dset[:] = y
print(dset.shape)
for i in range(3):
dset.resize(dset.shape[0] + 1, axis=0)
dset["somedata"] = y
some = h5py.File("out.h5", "r")
for x in some["somedata"]:
print(x)
But it is throwing me an error:
File "/anaconda3/lib/python3.7/site-packages/h5py/_hl/dataset.py", line 582, in __setitem__
raise TypeError("Illegal slicing argument (not a compound dataset)")
TypeError: Illegal slicing argument (not a compound dataset)
dset["somedata"]?dsetis the dataset object. You used it correctly withdset[:]=y. I thinksome["somedata"]is correct.df.to_hdfwithmode='a': pandas.pydata.org/pandas-docs/stable/reference/api/…dset[-1:] = y