# Adding a custom column to a RDataFrame

**URL:** <https://root-forum.cern.ch/t/adding-a-custom-column-to-a-rdataframe/46154>\
**Category:** Newbie\
**Tags:** rdataframe, python\
**Created:** [August 3, 2021, 5:32pm UTC](https://root-forum.cern.ch/t/adding-a-custom-column-to-a-rdataframe/46154 "2021-08-03T17:32:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michele99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele99/32/27318_2.png) [@Michele99](https://root-forum.cern.ch/u/Michele99)\
**Post date:** [August 3, 2021, 5:32pm UTC](https://root-forum.cern.ch/t/adding-a-custom-column-to-a-rdataframe/46154/1 "2021-08-03T17:32:32Z")

</div>

Hi, I would like to create a new column basing on the value of another variable in the dataframe for each entry.  
What I would like to do is to have a column called “C\_origin” which is filled for every entry with 1 if TrackOrigin is equal to 2, and with 0 for all the other TrackOrigin values.  
What I tried to do is: dataframe.Define(“C\_origin”, “1” if ‘TrackOrigin’==2 else “0”) but this doesn’t seem to work.  
I’m currently using python.  
Cheers, Michele

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [August 4, 2021, 10:52am UTC](https://root-forum.cern.ch/t/adding-a-custom-column-to-a-rdataframe/46154/2 "2021-08-04T10:52:58Z")

</div>

```python
dataframe.Define("C_origin", "TrackOrigin==2 ? 1 : 0")

```

might work?

---

<div class="post-metadata">

**Author:** ![Michele99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele99/32/27318_2.png) [@Michele99](https://root-forum.cern.ch/u/Michele99)\
**Post date:** [August 4, 2021, 2:17pm UTC](https://root-forum.cern.ch/t/adding-a-custom-column-to-a-rdataframe/46154/3 "2021-08-04T14:17:22Z")

</div>

Thanks really much, it worked!
