# "Unknown column" when attempting to Snapshot an RDataFrame with a new, Defined column

**URL:** <https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915>\
**Category:** Newbie\
**Created:** [September 21, 2021, 2:55am UTC](https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915 "2021-09-21T02:55:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KAM](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kam/32/37110_2.png) [@KAM](https://root-forum.cern.ch/u/KAM)\
**Post date:** [September 21, 2021, 2:55am UTC](https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915/1 "2021-09-21T02:55:35Z")

</div>

I’ve written the following code, which takes in two files (`test1.root` and `test2.root`) in an `RDataFrame`. Each contains a `TNtuple` with the columns/branches `x` and `y`.

I then define a new column, `z`, produced by taking the element-wise product of the two columns.

Finally, I attempt to store the `RDataFrame` as a `TTree` in a `.root` file.

Here’s my code:

```auto
vector<string> file_list = {"test1.root", "test2.root"};
ROOT::RDataFrame df("N", file_list);

df.Define("z", [](int a, int b){ return a * b; },{"x","y"});
df.Snapshot("N", "test4.root", {"x","y","z"});

```

Unfortunately, this gives the error: `Unknown column: z"`. Where have I erred?

When I try storing only the `x` and `y` columns, all goes well.

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [September 21, 2021, 7:03am UTC](https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915/2 "2021-09-21T07:03:16Z")

</div>

Try like this:

```
auto df_z = df.Define("z", [](int a, int b){ return a * b; },{"x","y"});
df_z.Snapshot("N", "test4.root", {"x","y","z"});

```

Cheers,  
Jakob

---

<div class="post-metadata">

**Author:** ![RENATO\_QUAGLIANI](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renato_quagliani/32/19496_2.png) [@RENATO\_QUAGLIANI](https://root-forum.cern.ch/u/RENATO_QUAGLIANI)\
**Post date:** [September 21, 2021, 10:37pm UTC](https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915/3 "2021-09-21T22:37:37Z")

</div>

You can find useful as well to use RNode

ROOT::RDF::RNode myNode(df) ;

myNode =myNode.Define(…  
myNode.Snapshot(

The issue is that the df.Define you call create a processing graph node which is not used / known in the node used to Snapshot.

---

<div class="post-metadata">

**Author:** ![KAM](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kam/32/37110_2.png) [@KAM](https://root-forum.cern.ch/u/KAM)\
**Post date:** [September 25, 2021, 6:48pm UTC](https://root-forum.cern.ch/t/unknown-column-when-attempting-to-snapshot-an-rdataframe-with-a-new-defined-column/46915/4 "2021-09-25T18:48:50Z")

</div>

Thanks! This works great.
