# Sorting a DataFrame

**URL:** <https://root-forum.cern.ch/t/sorting-a-dataframe/31426>\
**Category:** ROOT\
**Created:** [November 2, 2018, 10:47pm UTC](https://root-forum.cern.ch/t/sorting-a-dataframe/31426 "2018-11-02T22:47:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [November 2, 2018, 10:47pm UTC](https://root-forum.cern.ch/t/sorting-a-dataframe/31426/1 "2018-11-02T22:47:42Z")

</div>

Would it be possible to sort a DataFrame using a particular column ?

* * *

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [November 3, 2018, 8:48am UTC](https://root-forum.cern.ch/t/sorting-a-dataframe/31426/2 "2018-11-03T08:48:16Z")

</div>

Hi Eddy,

this is presently not possible. We will introduce this capability for cached datasets only, i.e. in memory, for 6.18.  
From your expert perspective, how would you see this interface? Would a sorting upon caching enough or you would need to re-sort at any point in time?

```auto
mySortedImmutableRdf = myRdf.Cache("", {"sortCol1", "sortCol2"});
// or 
mySortableRdf = myRdf.Cache();
ROOT::RDF::Sort(mySortableRdf, {"sortCol1", "sortCol2"});

```

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [November 3, 2018, 5:42pm UTC](https://root-forum.cern.ch/t/sorting-a-dataframe/31426/3 "2018-11-03T17:42:57Z")

</div>

Hi Danillo,

For my use case only one sort would be done . Just so that I understand the  
interface. I would like to sort the rows of a RDataFrame by using “sortCol1” as major index and possible “sortCol2” as minor index.

I would prefer option 2 just to separate aching and sorting.

Best Eddy

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [November 17, 2018, 5:43pm UTC](https://root-forum.cern.ch/t/sorting-a-dataframe/31426/4 "2018-11-17T17:43:00Z")

</div>

Closed on November 17, 2018, 5:43pm UTC

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