在熊猫系列上循环正则表达式

时间:2020-02-04 10:19:26

标签: regex python-3.x

我有一个单词列表,我想检查这些单词是否存在于数据框的“文本”列中。我写了正则表达式,我想将正则表达式循环到列上并提取匹配的单词,然后删除重复项以获得唯一的匹配单词。

regex_list = []
for lex in deplex_fin:
    regex_list.append('/(^|\W)'+lex+'($|\W)/i')


matching_words_list = []
for regex in regex_list:
    matching_words_df = neg_sent['cleanText_emrm'].str.extract(regex)
    matching_words = list(matching_words_df.iloc[:,0])
    for item in matching_words:
        if str(item) != 'nan':
            matching_words_list.append(item)

但这花费了太长时间-有没有更快的方法可以做到这一点?

0 个答案:

没有答案