# RDataFrame Aggregate within pyROOT

**URL:** <https://root-forum.cern.ch/t/rdataframe-aggregate-within-pyroot/52526>\
**Category:** ROOT\
**Tags:** python, rdataframe\
**Created:** [November 28, 2022, 4:29am UTC](https://root-forum.cern.ch/t/rdataframe-aggregate-within-pyroot/52526 "2022-11-28T04:29:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Silence2107](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/silence2107/32/22549_2.png) [@Silence2107](https://root-forum.cern.ch/u/Silence2107)\
**Post date:** [November 28, 2022, 5:31am UTC](https://root-forum.cern.ch/t/rdataframe-aggregate-within-pyroot/52526/2 "2022-11-28T05:31:42Z")

</div>

Technically I found at least one solution based on [link](https://root-forum.cern.ch/t/pyroot-rdataframe-reduce-vector-branch-typeerror/42981), but I suspect this one is not the most elegant.

```auto
ROOT.EnableImplicitMT()
rdf = ROOT.ROOT.RDataFrame(10)
rdf = rdf.Define("x", "return rdfentry_;")
rdf = rdf.Define("x_sqr", "return rdfentry_*rdfentry_;")
#disp = rdf.Display("", 10)
#disp.Print()
ROOT.gInterpreter.Declare("""
struct Accumulator {
    ULong64_t operator()(ULong64_t acc, ULong64_t x) const { return acc + x; }
};
struct Combiner {
    ULong64_t operator()(ULong64_t acc1, ULong64_t acc2) const { return acc1 + acc2; }
};
""")
sum = rdf.Aggregate(ROOT.Accumulator(), ROOT.Combiner(), "x").GetValue()

```

Please let me know if you know a better way.

---

_[View the full topic](https://root-forum.cern.ch/t/rdataframe-aggregate-within-pyroot/52526)._
