# Is there a way to save dataframe to an already existing root file?

**URL:** <https://root-forum.cern.ch/t/is-there-a-way-to-save-dataframe-to-an-already-existing-root-file/45974>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [July 22, 2021, 2:18pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-save-dataframe-to-an-already-existing-root-file/45974 "2021-07-22T14:18:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 22, 2021, 3:07pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-save-dataframe-to-an-already-existing-root-file/45974/4 "2021-07-22T15:07:49Z")

</div>

We must be doing something different. This works for me:

```cpp
#include <ROOT/RDataFrame.hxx>

int main() {
   auto df = ROOT::RDataFrame(10).Define("x", [] { return 42; });

   // produce initial file
   df.Snapshot<int>("t1", "f.root", {"x"});

   // write another tree to that file
   ROOT::RDF::RSnapshotOptions opts1;
   opts1.fMode = "update";
   df.Snapshot<int>("t2", "f.root", {"x"}, opts1);

   // overwrite the t1
   ROOT::RDF::RSnapshotOptions opts2;
   opts2.fMode = "update";
   opts2.fOverwriteIfExists = true;
   df.Range(5).Snapshot<int>("t1", "f.root", {"x"}, opts2);

   return 0;
}

```

At the end of the program `f.root` contains `t1` with 5 entries and `t2` with 10. What am I doing differently?

Cheers,  
Enrico

---

_[View the full topic](https://root-forum.cern.ch/t/is-there-a-way-to-save-dataframe-to-an-already-existing-root-file/45974)._
