Contains with Lowercase
Hi Team,
I have a dataset which one column consisting of multiple values, for example
Column1
Metric1,Country
METRIC1,Country
METRIC1,Country
Metric2,Country
Is there a work around to filter the values in the column to only keep the value that contains 'Metric1' regardless of the case.
The result should be:
Column1
Metric1,Country
METRIC1,Country
METRIC1,Country
I tried the below query but it does not work.
( contains(toLowercase(val('Column1')), toLowercase(val('METRIC1'))) )
Please assist.
Best Answer
-
Hello, I think you have an extra "val" in your formula. Can you please try:
contains(toLowercase(val('Column1')), 'metric1')
Answers
-
Manuel Alpha Tester, Dataiker Alumni, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Dataiku DSS Adv Designer, Registered Posts: 193 ✭✭✭✭✭✭✭
Hi,
In a Prepare recipe you can use the "Extract with Regular Expression" processor, which will allow you to identify the rows that contain Metric1 in either lowercase or uppercase.
https://doc.dataiku.com/dss/latest/preparation/processors/pattern-extract.html
To help you with the regex expression, use the smart pattern builder and select the right values
I hope this helps.
Best regards
-
Hi MarcH,
This solution works for me ! Thanks! Additionally can you help to elaborate further what does the val() function really represents here? Cause if i tried to remove the val() function, it does not work.
contains(toLowercase(val('Column1')), 'metric1')
-
Hello, good to hear! The val() function returns the value of the column whose name you give as an argument (the column named 'Column1' in your example). If you just put 'Column1' without the val(), you'll just get a String that always has a value of 'Column1', like was done for 'metric1' in your example.