我正在尝试在数据框中搜索特定单词,并在搜索单词之后和搜索单词之前获得3个单词

时间:2019-06-10 12:19:25

标签: python regex

在手动输入中可以正常工作。如果在循环中应用相同的东西。我收到错误消息IndexError: single positional indexer is out-of-bounds

x="entry"
new=R_data[R_data['Critical Observation'].str.contains(x)]
# y="physical petty cash per system difference petty cash balance maintained real time basis postponement making entry updating system cause difference"
y=new['Critical Observation'].astype(str)
type(y)
match=re.search("(\w+) (\w+) (\w+) "+(str(x))+" (\w+) (\w+) (\w+)",y.iloc[0])
print(match.group(0))
for x in Dict["Key Words"].iloc[0:5]:
    new=R_data[R_data['Critical Observation'].str.contains(x)]
    y=new['Critical Observation'].astype(str)
    match=re.search("(\w+) (\w+) (\w+) "+(str(x))+" (\w+) (\w+) (\w+)",y.iloc[0])
    match.group(0)

我想要R_data['Critical Observation']中每个关键字的三个单词之前和之后。

0 个答案:

没有答案