首页 > 解决方案 > 使 for 循环附加在所有数据集上

问题描述

我正在尝试将 for 循环附加到范围内的所有数据集上,(0,8675)但仅使用 1 行时它会不断出错

def convert_emoticons(text):
    for emot in EMOTICONS:
        text = re.sub(u'('+emot+')', "_".join(EMOTICONS[emot].replace(",","").split()), text)
    return text

text = (dataset['posts'][0])
convert_emoticons(text)

标签: pythonfunctionfor-loop

解决方案


尝试使用emot

def convert_emoticons(text):
    for emot in EMOTICONS:
        text = re.sub(u'('+emot+')', "_".join(emot.replace(",","").split()), text)
    return text

text = (dataset['posts'][0])
convert_emoticons(text)

推荐阅读