I'm trying to create a function called "words_in_texts" to get the result like this
words_in_texts(['hello', 'bye', 'world'],
pd.Series(['hello', 'hello world hello'])
array([[1, 0, 0],
[1, 0, 1]])
I believe that the argument for this function should be a list with all the words and a series.
def words_in_texts(words, texts):
'''
Args:
words (list-like): words to find
texts (Series): strings to search in
Returns:
NumPy array of 0s and 1s with shape (n, p) where n is the
number of texts and p is the number of words.
'''
indicator_array = texts.str.contains(words)
return indicator_array
I'm confused on how to create the 2d array result, can anyone please help me with this? Thank you in advance!