[英]How to insert/edit a column in an existing HDF5 dataset
除非您首先具有用於創建HDF5文件的方案/規范,否則這是不可能的。
如果您嘗試使用HDF5文件(如電子表格)(甚至通過h5py),可能會出錯。 例如:
您可以做的是將列表作為屬性添加到數據集。 實際上,這可能是正確的事情。 下面的示例代碼,輸入為字典。 當您讀入數據時,會將屬性鏈接到同類數據(按行,列或其他標識符)。
def add_attributes(hdf_file, attributes, path='/'):
"""Add or change attributes in path provided.
Default path is root group.
"""
assert os.path.isfile(hdf_file), "File Not Found Exception '{0}'.".format(hdf_file)
assert isinstance(attributes, dict), "attributes argument must be a key: value dictionary: {0}".format(type(attributes))
with h5py.File(hdf_file, 'r+') as hdf:
for k, v in attributes.items():
hdf[path].attrs[k] = v
return "The following attributes have been added or updated: {0}".format(list(attributes.keys()))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.