RDataFrame filter on a string column

_ROOT Version: 6.18.04
_Platform: OSX
_Compiler: clang

I am using RDataFrame to analyze some data in a csv. The data contain few column which are string.
I would like to filter the data on that string column. Here my example. “descr” is the column name and “ICU_N_Voltage” is the value.

root [2] auto h1 = df.Filter(“descr == ICU_N_Voltage”).Histo1D(“engValue”)
input_line_17:2:17: error: use of undeclared identifier ‘ICU_N_Voltage’
return descr == ICU_N_Voltage
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Cannot interpret the following expression:
descr == ICU_N_Voltage

Make sure it is valid C++.

How can I make it working?
Thanks a lot

Hi and welcome to the ROOT forum!
Can you share the CSV or at least a couple of its rows?

Thanks for the quick replay.
In the mean time I have try to use lambda function in the filter

root [2] auto typeCut = [](std::string x) { return x == “ICU_N_Voltage”; };
root [3] auto h1 = df.Filter(typeCut, {“descr”}).Histo1D(“engValue”)
(ROOT::RDF::RResultPtr &) @0x1079f6360

and it works.

Here few lines of my CSV file.



Ah, then that’s your problem, if "ICU_N_Voltage" is a string constant and not a column name C++ syntax requires surrounding commas:

df.Filter("descr == \"ICU_N_Voltage\"")


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