【发布时间】:2021-09-30 13:22:56
【问题描述】:
我有一个包含句子的数据框,我想使用 str.contains 来找出句子是否包含单词,然后将找到的单词添加到数据框的列中。 例如:输入
dataset['sentence']
0 I am using a macbookpro and I like it.
1 I am using dell with windows OS and I love it.
........
searchfor = '|'.join(searchfor)
searchfor
0 windows|macbook|love
dataset['Match']=dataset['sentence'].str.contains(searchfor)
dataset['Matchcount']=dataset['sentence'].str.count(searchfor)
**Expected Output:**
sentence Match Matched Word Matchcount
I am using a macbookpro and I like it. True macbook 1
I am using dell with windows OS and I love it. True windows,love 2
如何在输出中获得“匹配的单词”? 谢谢
【问题讨论】:
标签: python dataframe nlp substring contains