Sort a RDataFrame

Hello everyone

Can I please ask, is it now possible to sort a (cached) dataframe? This thread suggests it is for my current version of Root: 31426 (sorry, not allowed to post links - search for “sorting a dataframe”).

However, I cannot see how to do this. Any suggestions? Thanks!

ROOT Version: 6.26.4
Platform: Debian
Compiler: g++

Welcome to the ROOT Forum! I’m sure @eguiraud will help you

Hi @Yannis_Kingdom ,

and welcome to the ROOT forum! Indeed the thread you mention (Sorting a DataFrame) stated the feature would be available in v6.18, but that was never actually implemented in RDataFrame itself, unfortunately. If your data fits in RAM, in Python you can export it to numpy arrays with AsNumpy (after RDF filtering and processing), then use pandas to sort the dataset, then if needed you can construct another RDataFrame from that pandas dataframe with

arrs = {k: np.array(v) for k,v in pandas_df.to_dict().items()}
rdf = ROOT.RDF.MakeNumpyDataFrame(arrs)

It’s possible to do something similar in C++ but it requires a lot more code.


Thank you, Enrico! I have actually written a procedure to sort a panel of data in C++, I was just wondering if this was a feature native to Root - I can now proceed with my code :slight_smile: