# RDataFrame, a modern tool to manipulate and analyze ROOT datasets

**URL:** <https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384>\
**Category:** News\
**Tags:** rdataframe\
**Created:** [June 15, 2018, 11:50am UTC](https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384 "2018-06-15T11:50:09Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [June 15, 2018, 11:50am UTC](https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384/1 "2018-06-15T11:50:10Z")

</div>

**What is `RDataFrame`?**

`ROOT::RDataFrame` is a modern C++ high-level interface for interacting with data in ROOT.  
It spent its infancy in the namespace `ROOT::Experimental`, and with v6.14, [released yesterday](https://root-forum.cern.ch/t/root-production-release-v6-14-00-is-out), it became officially part of ROOT.

The interface design is inspired by other dataframe APIs such as `pandas` or Spark `DataFrames`; it also takes ideas from the functional and declarative programming paradigms.  
`RDataFrame`, however, is specially crafted for HEP use-cases and ROOT users. For example:

- it reads ROOT data as well as CSVs, Arrow tables, and it can be extended to [arbitrary data formats](https://github.com/bluehood/mdfds)
- among others, it exposes methods to easily fill ROOT 1D, 2D, 3D histograms, profiles, and retrieve information on cut-flows, and its functionality can be extended by end users
- it allows to easily generate ROOT data from scratch or write out a skimmed, trimmed dataset
- all of the above is parallelized with one line of code which activates ROOT’s [implicit multi-threading](https://root.cern/doc/master/namespaceROOT.html#a06f2b8b216b615e5abbc872c9feff40f)
- for python users, `RDataFrame` comes with pyROOT bindings

**How does this look?**  
This is a simple cut-and-fill with `RDataFrame`:

```auto
ROOT::RDataFrame df("mytree", {"f1.root", "f2.root"});
auto h = df.Filter("x > 0").Histo1D("x");
h->Draw(); // the event loop is run here, upon first access to one of the results

```

The lazy triggering of the event loop makes it easy to generate multiple results while reading the data only once:

```auto
// C++11 lambdas and functions are also supported as filter expressions
auto filtered_df = df.Filter([](float x) { return x > 0; }, {"x"});
auto hx = filtered_df.Histo1D("x");
auto hy = filtered_df.Histo1D("y");
hx->Draw(); // event loop is run here, both hx and hy are filled

```

As a last example, let’s filter the events, define a new quantity, produce a control plot _and_ write out the filtered dataset, all in the same multi-thread event loop:

```auto
ROOT::EnableImplicitMT(); // enable multi-threading
ROOT::RDataFrame df(treename, filenames); // create dataframe
auto df2 = df.Filter("x > 0").Define("y", "x*x"); // filter and define new column
auto control_h = df2.Histo1D("y"); // book filling of a control plot
// write out new dataset. this triggers the event loop and also fills the booked control plot
df2.Snapshot("newtree", "newfile.root", {"x","y"});

```

More information, a quick crash course and a cheat-sheet are available as part of [RDataFrame’s guide](https://root.cern/doc/master/classROOT_1_1RDataFrame.html).  
C++ and python tutorials are available [here](https://root.cern.ch/doc/master/group __tutorial__ dataframe.html).

**What’s in `RDataFrame`'s future?**  
Work is in progress to make the pyROOT bindings more pythonic, and to let users define an `RDataFrame` analysis and execute it as is, either locally on multiple cores or distributed over a CPU cluster (e.g. a Spark cluster).  
We are listening to the feedback of early adopters to keep improving `RDataFrame` and fix its rough edges: users’ feedback is greatly welcome, either on this forum as a question, a discussion, or on ROOT’s [jira](https://sft.its.cern.ch/jira/projects/ROOT/issues/ROOT-9472?filter=allopenissues) as a bug report!

---

<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:** [June 15, 2018, 12:57pm UTC](https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384/2 "2018-06-15T12:57:17Z")

</div>

Pinned on June 15, 2018, 12:57pm UTC



---

<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:** [June 29, 2018, 12:57pm UTC](https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384/3 "2018-06-29T12:57:18Z")

</div>

Closed on June 29, 2018, 12:57pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
