使用另一个列表中的关键字列表进行模式匹配,如果else category匹配为blan,则重新映射到后续类别

2024-09-24 08:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下:

Matched =np.array([False]*NewAGs.shape[0])
NewAGs["Tower"] = np.nan

for rowNum in range(Keywords.shape[0]):

    ## Get the keyword in the current row.
    keyword = Keywords.lowerKeywords[rowNum]
    ## Get Assignment groups with the keyword:
    index = (re.search("^" + keyword + "[^w+]", NewAGs.lowerAG[0]) or
    re.search("[^w+]"+keyword+"[^w+]", NewAGs.lowerAG[0]) or
    re.search("[^w+]"+keyword+"$", NewAGs.lowerAG[0]) or
    re.search("^"+keyword+"$", NewAGs.lowerAG[0]))
    print(bool(index))
    ## Select Only the Unmatched Assignment groups:

    index = index and index != -1
    print(sum(index))

    if index != 0
    NewAGs['Tower'[index]] <- Keywords['Tower'[rowNum]]
    Matched <- Matched or index

Tags: ortheinresearchindexnpkeyword