# H5py adding more data to an existing dataset

**URL:** <https://forum.hdfgroup.org/t/h5py-adding-more-data-to-an-existing-dataset/6784>\
**Category:** HDF5 Library\
**Created:** [March 9, 2020, 3:40pm UTC](https://forum.hdfgroup.org/t/h5py-adding-more-data-to-an-existing-dataset/6784 "2020-03-09T15:40:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylan.rambarose](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dylan.rambarose](https://forum.hdfgroup.org/u/dylan.rambarose)\
**Post date:** [March 9, 2020, 3:40pm UTC](https://forum.hdfgroup.org/t/h5py-adding-more-data-to-an-existing-dataset/6784/1 "2020-03-09T15:40:05Z")

</div>

My question is i create a h5py file, in python create my dataset and write my data to the dataset in the file then close the file this is the part i cant figure out how to do can i open back the file and continue to write more data to the existing dataset without overwriting and losing my existing data in my dataset

---

<div class="post-metadata">

**Author:** ![thomas1](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/thomas1/32/1733_2.png) [@thomas1](https://forum.hdfgroup.org/u/thomas1)\
**Post date:** [March 12, 2020, 1:46pm UTC](https://forum.hdfgroup.org/t/h5py-adding-more-data-to-an-existing-dataset/6784/2 "2020-03-12T13:46:05Z")

</div>

You’ll need to use the `'r+'` or `'a'` mode when you reopen the file, to get read/write access without replacing the existing data. Docs: [http://docs.h5py.org/en/stable/high/file.html#opening-creating-files](http://docs.h5py.org/en/stable/high/file.html#opening-creating-files)

If you left empty space in your dataset when you first wrote to it, you can write to that as per normal (`dataset[x:y] = data`). If not, you will need to resize the dataset to make room for your new data. Docs: [http://docs.h5py.org/en/stable/high/dataset.html#resizable-datasets](http://docs.h5py.org/en/stable/high/dataset.html#resizable-datasets)

---

<div class="post-metadata">

**Author:** ![dylan.rambarose](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dylan.rambarose](https://forum.hdfgroup.org/u/dylan.rambarose)\
**Post date:** [March 13, 2020, 1:06pm UTC](https://forum.hdfgroup.org/t/h5py-adding-more-data-to-an-existing-dataset/6784/3 "2020-03-13T13:06:12Z")

</div>

Thank you very much fore the advice

I’ll give it a try and I hope if I have any more questions I can ask you .

 ![](https://hdf-discourse-1.s3.amazonaws.com/original/2X/7/7159a975d714a6caee787759490140daf4d4fda6.png)
