【问题标题】:How do I check each word of a string with each word of other string?如何检查字符串的每个单词与其他字符串的每个单词?
【发布时间】:2019-07-23 14:50:30
【问题描述】:

这是我的参考,我想用这个列表检查我的列表,然后根据 POS 和 NEG 的总和进行评分

我是 python 新手,所以这可能很容易。我正在参考数据集计算字符串的情感分数,该数据集具有 +ve 和 -ve 分数的单词列表。因此,如果我从参考数据集中的测试集中找到单词,我想添加 +ve 分数并减去 -ve 分数。为此,我必须从测试字符串中访问每个单词并检查参考数据集。 这是我的代码:


for i in range(0,29):
    my_string = processed[i]
    for word in my_string.split():
        for j in range(0,3013):
            senti_words=senti['LIST_OF_WORDS'].iloc[j,4]
            if  word in senti_words:
               pos=senti['LIST_OF_WORDS'].iloc[j,2]
               neg=senti['LIST_OF_WORDS'].iloc[j,3]
               sentiment=pos-neg
               a=a.append(sentiment)

【问题讨论】:

  • if条件格式错误
  • @tawab_shakeel 任何建议将不胜感激谢谢
  • 请添加示例数据和所需结果
  • 我已编辑您问题中的代码,出现语法错误
  • 我还应该应用什么语句来跳过不匹配的单词?

标签: python-3.x pandas nlp sentiment-analysis


【解决方案1】:

我可以在 if 块之后看到缩进错误,我没有要尝试的 senti 值,所以试试这个。

for i in range(0,29):
    my_string = processed[i]
    for word in my_string.split():
        for j in range(0,3013):
            senti_words=senti['LIST_OF_WORDS'].iloc[j,4]
            if  word in senti_words:
                pos=senti['LIST_OF_WORDS'].iloc[j,2]
                neg=senti['LIST_OF_WORDS'].iloc[j,3]
                sentiment=pos-neg
                a=a.append(sentiment)

【讨论】:

    猜你喜欢
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多