Hello.
I have a data table showing tweet comments on column 0. I would like to select specific rows of comments by matching a keyword found in the comment string. Is the evaluateDAT component the right one? thanks
Hello.
I have a data table showing tweet comments on column 0. I would like to select specific rows of comments by matching a keyword found in the comment string. Is the evaluateDAT component the right one? thanks
Hello evg, welcome to the forum.
I tried using a Select DAT, selecting row by condition and typed the expression
re.search('pink|planet|hello',me.inputCell.val) != None
where “pink”, “planet” and “hello” are my keywords.
It seemed to work but didn’t have time to fully investigate & test.
I found some tips about python re.match
and re.search
on stackoverflow.com
I hope that helps! (although I am not 100% sure that this is the right way to approach this, definitely it isn’t the only way)
Hey Fausto,
Thanks! I did not know about re.search on the selectDAT, its exactly what I was looking for.
best
Regular expressions are great. Just wanted to show non regular expression Python for this search:
any(x in me.inputCell.val for x in [‘pink’, ‘planet’, ‘hello’])
You can also use “all” instead of “any” to check if all the strings are there.
Thank you @Ivan for suggesting that alternative solution, it works very well!
For @evg, I’ve noticed that both mine and Ivan’s approaches do not handle very well the upper case scenarios. For example, in your table with the comments, if the word ‘hello’ is typed ‘Hello’ instead, using the type of syntax we have suggested won’t detect the message anymore. Fair enough.
Try instead
re.search('pink|planet|hello',me.inputCell.val.lower()) != None
or if you prefer Ivan’s approach try
any(x in me.inputCell.val.lower() for x in ['pink', 'planet', 'hello'])
After me.inputCell.val
I’ve added .lower()
to handle that scenario.
Based on my quick testing is seems to be working well!
File attached
Select DAT from keyword.toe (3.7 KB)
this is great, Thanks! @FaustoB