【发布时间】:2018-12-17 07:17:24
【问题描述】:
我有一个 DataFrame df_sentences 和一个 List question_words 如下:
df_sentences:
sentence label
you will not forget this movie 0
will the novel ever die 1
why we drink alcohol 1
did trump win the election 1
ambiance is perfect 0
question_words = ['what', 'why', 'when', 'where', 'whose', 'which', 'whom', 'who', 'how',
'do', 'are', 'will', 'did', 'will', 'am', 'are', 'was', 'were', 'can', 'has', 'have']
我想检查sentence 列的第一个单词是否存在于列表question_words 中,并将结果返回到新列ques_word。
预期输出:
sentence label ques_word
you will not forget this movie 0 0
will the novel ever die 1 1
why we drink alcohol 1 1
did trump win the election 1 1
the ambiance is perfect 0 0
到目前为止,我尝试的是使用.str.contains('|'.join(question_words)).astype(int),但正如预期的那样,它返回与question_words 列表匹配的所有子字符串的所有数量。
【问题讨论】: