# Finding differences between rows from PyROOT

**URL:** <https://root-forum.cern.ch/t/finding-differences-between-rows-from-pyroot/52067>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [October 24, 2022, 12:41am UTC](https://root-forum.cern.ch/t/finding-differences-between-rows-from-pyroot/52067 "2022-10-24T00:41:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atasattari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atasattari/32/30540_2.png) [@atasattari](https://root-forum.cern.ch/u/atasattari)\
**Post date:** [October 24, 2022, 12:41am UTC](https://root-forum.cern.ch/t/finding-differences-between-rows-from-pyroot/52067/1 "2022-10-24T00:41:48Z")

</div>

Hi,  
I tried to follow the previous post to compute some quantities between rows using PyROOT. I could declare a struct similar to the suggestion, but the output of the RDataFame is not as expected.  
My function:

```auto
ROOT.gInterpreter.Declare('''
struct diff {
  Double_t prevSeries = -1;
  Double_t firstTime = -1;
  double operator()(Double_t x, Double_t y) {
    if (prevSeries != x) {
      prevSeries = x;
      firstTime = y; 
    }
    Double_t diff = y - firstTime;
    return diff;
  }
};
''')

```

RdataFrame call:  
df = df.Range(10)  
df = df.Define(‘livetime’,‘diff()(SeriesNumber,timestamp\_corr)’)  
df = df.AsNumpy({‘livetime’,‘SeriesNumber’,‘timestamp\_corr’})  
Output:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/4/74fe90a1de8ec3465808dde8751db28ae721a7d4.png)  
Note that SeriesNumbers are all the same.  
Also, the 3 input overload of Define() didn’t work from PyROOT.

\_ROOT Version: 6.22/6.26

---

<div class="post-metadata">

**Author:** ![atasattari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atasattari/32/30540_2.png) [@atasattari](https://root-forum.cern.ch/u/atasattari)\
**Post date:** [October 24, 2022, 1:05am UTC](https://root-forum.cern.ch/t/finding-differences-between-rows-from-pyroot/52067/2 "2022-10-24T01:05:25Z")

</div>

I just needed to declare an instance of the diff, and use the instance in the Define().

```auto
ROOT.gInterpreter.Declare('''diff diff_instance;''')
df = df.Define('livetime','diff_instance(SeriesNumber,timestamp_corr)')

```
