I have a dataframe all_articles
with the columns ['title', 'astract']
.
I have written a function to do a boolean search on one column:
def searchString(string):
if ((('apple' or 'banana') and ('fork' or 'knife') and ('red' or 'green'))) in string:
return True
return False
Now, I want to create a column that contains true if the combination of the title
or abstract
fulfills the requirement of my boolean search. As an example, suppose that my dataframe looks as follows:
title abstract
'apple' 'red fork'
'orange' 'apple red fork'
'knife banana red' 'green bowl'
Then, I wish my function returns: ['True','True','False']
.
My current apply command looks as follows:
all_articles['boolean'] = all_articles['Abstract'].astype(str).apply(searchString)
Obviously, I could create a column in which I merge title
and abstract
and apply the function on that column. However, I am curious if there are ways to do this through an apply function that has 2 columns of input.