【发布时间】:2018-10-02 04:33:18
【问题描述】:
我正在尝试创建一个名为“words_in_texts”的函数来获得这样的结果
words_in_texts(['hello', 'bye', 'world'],
pd.Series(['hello', 'hello world hello'])
array([[1, 0, 0],
[1, 0, 1]])
我认为这个函数的参数应该是一个包含所有单词和一个系列的列表。
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
我对如何创建二维数组结果感到困惑,谁能帮我解决这个问题?提前谢谢!
【问题讨论】: