在熊猫系列中找到一个单词的完全匹配

时间:2019-08-27 14:47:39

标签: python

我下面有一个数据框

news                 score
testing tools           12
test match              32
he is testing           332
test is done             23

我想要这样的结果

news                        score
test match                   32
test is done                 23

ddf[ddf['news'].str.contains('test', regex= False)]

ddf[ddf['news'].str.contains('test', regex= False)]

1 个答案:

答案 0 :(得分:0)

尝试一下:

pattern = '/\btest\b/'
ddf[ddf['news'].str.contains(pattern, regex= True)]

有关正则表达式模式的更多信息,请阅读: https://stackoverflow.com/a/13065780/2754195