第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何抑制 Python 庫 TextBlob 的一些輸出

如何抑制 Python 庫 TextBlob 的一些輸出

侃侃爾雅 2022-06-07 16:55:42
我正在使用 Python 為從 TextBlob 返回的結果分配標簽。我非?;镜拇a如下所示:from textblob import TextBlobdef sentLabel(blob):    label = blob.sentiment.polarity     if(label == 0.0):        print('Neutral')    elif(label > 0.0):        print('Positive')    else:        print('Negative')    Feedback1 = "The food in the canteen was awesome"    Feedback2 = "The food in the canteen was awful"    Feedback3 = "The canteen has food"    b1 = TextBlob(Feedback1)    b2 = TextBlob(Feedback2)    b3 = TextBlob(Feedback3)    print(b1.sentiment_assessments)    print(sentLabel(b1))    print(b2.sentiment_assessments)    print(sentLabel(b2))    print(b3.sentiment_assessments)    print(sentLabel(b3))這會正確打印出情緒,但也會打印出“無”,如下所示:Sentiment(polarity=1.0, subjectivity=1.0, assessments=[(['awesome'], 1.0, 1.0, None)])PositiveNone...有什么辦法可以禁止打印“無”?感謝您的任何幫助或指點。
查看完整描述

1 回答

?
三國紛爭

TA貢獻1804條經(jīng)驗 獲得超7個贊

你的函數(shù)sentLabelreturn None。因此,當您使用時print(sentLabel(b1)),它會打印None.


這應該適合你。


from textblob import TextBlob


def sentLabel(blob):

    label = blob.sentiment.polarity 


    if(label == 0.0):

        print('Neutral')

    elif(label > 0.0):

        print('Positive')

    else:

        print('Negative')


    Feedback1 = "The food in the canteen was awesome"

    Feedback2 = "The food in the canteen was awful"

    Feedback3 = "The canteen has food"



    b1 = TextBlob(Feedback1)

    b2 = TextBlob(Feedback2)

    b3 = TextBlob(Feedback3)


    print(b1.sentiment_assessments)

    sentLabel(b1)

    print(b2.sentiment_assessments)

    sentLabel(b2)

    print(b3.sentiment_assessments)

    sentLabel(b3)


查看完整回答
反對 回復 2022-06-07
  • 1 回答
  • 0 關注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號