如何替换附加的内容

How do I replace something that is on an append

我必须替换我正在阅读的 txt 文件中的一些单词。我使用附加将它们分开,[0] 用于确定情绪的词,[1] 用于文本的其余部分。

# Opens the corpus
f = open("analise-sentimentos-2000-noticias.txt", "r", encoding="utf-8-sig")
linhas = f.readlines()

corpus_textos = []
corpus_rotulos = []

# Goes through 2000 lines
for linha in linhas:

  # Separate text and label/category/emotion
  item = linha.split(";;")

  corpus_rotulos.append(item[0])
  corpus_textos.append(item[1])

而且我需要替换append [0]中的单词,我该怎么做?这是我正在处理的一些文本:

我已将需要替换的词突出显示为黄色,例如,'alegria' 应替换为 'positivo'。紫色是我需要排除的行(如果行以情感 'surpresa' 开头,我需要排除它)。我该怎么做?

作为参考,我正在使用 Google Colab 进行情绪分析。 txt 已上传到我的驱动器。

首先检查 surpresa 以跳过这些行。然后你可以在添加到列表时在类别中进行替换。

for linha in linhas:
    # Separate text and label/category/emotion
    rotulo, texto = linha.split(";;")

    if rotulo != 'surpresa':
        corpus_rotulos.append(rotulo.replace('alegria', 'positivo'))
        corpus_textos.append(texto)