RDataFrame count elements in column by value

Hello everyone,

first off, great job with RDataFrame. It is such a great tool to have. I have one minor question: Is there a function which is able to count the occurrence of values within a specific column? Lets say I apply a filter and have column called ‘event_nr’. I would like to count how many times a certain ‘event_nr’ appears after applying that filter. In python pandas there is a function called ‘value_count’. Is there something similar for RDataFrames? Thanks a lot in advance.

Hi @dlersch ,
and welcome to the ROOT forum!

We don’t have a df.ValueCount(..) but you can implement it via df.Aggregate or df.Book (Aggregate is simpler, Book is more powerful, see the docs).

For example you can Aggregate column values into a std::map value → count. The implementation of the aggregation and reductions has to be C++ but you can then put things together from Python as usual.

Cheers,
Enrico

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