Python 使用pandas str.contains(';';.join(字符串列表))获取为给定字符串列表的每一行找到的字符串

Python 使用pandas str.contains(';';.join(字符串列表))获取为给定字符串列表的每一行找到的字符串,python,pandas,Python,Pandas,Im使用Pandasstr.contains在给定字符串列表的列中查找字符串。例如: matched_rows = data[data['Description'].str.contains('|'.join(search_terms))] search_terms是一个字符串列表,因此上面的表达式返回包含这些字符串的所有行(使用'|'。连接(search_terms)以获取其描述包含string1、string2或string3等的任何行。) 如何确定在每行中实际找到了哪个字符串?我的字符串

Im使用Pandas
str.contains
在给定字符串列表的列中查找字符串。例如:

matched_rows = data[data['Description'].str.contains('|'.join(search_terms))]
search_terms
是一个字符串列表,因此上面的表达式返回包含这些字符串的所有行(使用
'|'。连接(search_terms)
以获取其描述包含string1、string2或string3等的任何行。)


如何确定在每行中实际找到了哪个字符串?我的字符串列表超过100个元素,因此,当找到一个字符串时,我实际上无法通过查看返回的行来判断立即找到了什么。我正在寻找一种识别“误报”的方法。

一种方法是使用
.str.extract(f“({'.'.join(search_terms)})”)
试试看。这很有效,谢谢