# RDataFrame: Define: order of columns

**URL:** <https://root-forum.cern.ch/t/rdataframe-define-order-of-columns/63128>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [March 13, 2025, 1:42pm UTC](https://root-forum.cern.ch/t/rdataframe-define-order-of-columns/63128 "2025-03-13T13:42:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [March 13, 2025, 1:42pm UTC](https://root-forum.cern.ch/t/rdataframe-define-order-of-columns/63128/1 "2025-03-13T13:42:09Z")

</div>

_ROOT Version:_ 6.32.08  
_Platform:_ linuxx8664gcc  
_Compiler:_ c++ (Ubuntu 13.3.0-6ubuntu2~24.04)

* * *

Hello,

`RDataFrame` doesn’t seem to keep the order of `Define()`.

Here is a MWE:  
[print.C](https://root-forum.cern.ch/uploads/short-url/bFcyfNi365HAYbrnsTvevXbS8rO.C) (213 Bytes)

```cpp
void print(const string& name_1, const string& name_2) {
    ROOT::RDataFrame empty(0);
    auto rdf = empty.Define(name_1, [](){return 0;})
        .Define(name_2, [](){return 0;});
    rdf.Describe().Print();
}

```

Test 1: a b

```bash
$ root -q "print.C(\"a\", \"b\")"
   ------------------------------------------------------------------
  | Welcome to ROOT 6.32.08 https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jan 24 2025, 09:37:12 |
  | From tags/v6-32-08@v6-32-08 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

Processing print.C("a", "b")...
Empty dataframe filling 0 rows

Property Value
-------- -----
Columns in total 2
Columns from defines 2
Event loops run 0
Processing slots 1

Column Type Origin
------ ---- ------
a int Define
b int Define

```

Test 2 : b a

```bash
$ root -q "print.C(\"b\", \"a\")"
   ------------------------------------------------------------------
  | Welcome to ROOT 6.32.08 https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jan 24 2025, 09:37:12 |
  | From tags/v6-32-08@v6-32-08 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

Processing print.C("b", "a")...
Empty dataframe filling 0 rows

Property Value
-------- -----
Columns in total 2
Columns from defines 2
Event loops run 0
Processing slots 1

Column Type Origin
------ ---- ------
a int Define
b int Define

```

How can it keep the order of `Define()` ?

Best Regards,

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [March 13, 2025, 2:43pm UTC](https://root-forum.cern.ch/t/rdataframe-define-order-of-columns/63128/2 "2025-03-13T14:43:10Z")

</div>

Hello @Salomon!

RDataFrame doesn’t observe the order of Defines at all, but this has to do with how values are passed between nodes of the computation graph.  
When you `Define`, you assign a column name to some kind of function that produces a value. Just the fact that you defined it doesn’t mean, however, that the function will actually run. In order to run the function, you have to pass it into an action:  
When you use the column, you typically do `rdf.Action(xxx, {"a", "b"});`. Given that you pass the column by name, it doesn’t matter in which order they were defined. RDataFrame will evaluate a first and b second to supply values to this action. If you do `rdf.Action(xxx, {"b", "a"});`, they run in inverse order, irrespective of how they were defined.

When you use `Describe`, you get an alphabetical list of columns, which is independent of how you defined them.
