【问题标题】:Is there any alternative to set_value in pythonpython中的set_value是否有任何替代方法
【发布时间】:2021-03-08 07:04:23
【问题描述】:

我收到如下错误:“AttributeError: 'DataFrame' object has no attribute 'set_value'”。 代码在这里:

for i in range(0,len(text)):
   textB = TextBlob(text[i])
   sentiment = textB.sentiment.polarity
   new_df.set_value(i,'sentiment', sentiment)
   if sentiment < 0.00 :
       sentimentclass = 'Negative'
       new_df.set_value(i, 'sentimentclass', sentimentclass)
   elif sentiment > 0.00 :
       sentimentclass = 'Positive'
       new_df.set_value(i, 'sentimentclass', sentimentclass)
   else :
       sentimentclass = ' Neutral'
       new_df.set_value(i, 'sentimentclass', sentimentclass)

【问题讨论】:

    标签: python pandas dataframe sentiment-analysis


    【解决方案1】:

    set_value() 被标记为deprecated in 0.21。文档说你可以使用at[]

    df.at[row, column] = value
    

    应该是

    new_df.at[i, 'sentimentclass'] = sentimentclass
    

    在你的情况下

    【讨论】:

    • 谢谢,我做到了,但仍然出现错误:意外缩进
    • 这是一个正常的 Python 错误。检查代码的indentation
    猜你喜欢
    • 2012-02-21
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2020-01-30
    • 2023-03-27
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    相关资源
    最近更新 更多