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
S


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.

pk,name,descr,rawValue,engValue,monState,generationTime,rawValidity,engValidity,id,receivedTime,bitOffset,bitSize,sample,curve,limits,alert
796,ENNT1100,ICU_N_Voltage,0,0,OK,1579898482.28714,1,1,19,1579898482.289,168,32,1,ENNN111100,0
797,ENNT1101,DPU#1_N_Voltage,0,0,OK,1579898482.28714,1,1,19,1579898482.289,200,32,1,ENNN111100,0
798,ENNT1102,DPU#2_N_Voltage,0,0,OK,1579898482.28714,1,1,19,1579898482.289,232,32,1,ENNN111100,0
808,ENNT1112,ICU_N_Current,0,0,OK,1579898482.28714,1,1,19,1579898482.289,552,32,1,ENNN111101,0

Cheers

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\"")

Cheers,
Enrico

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