TextBlob情绪分析:价值观

2024-09-28 20:57:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我对情绪分析很陌生,我正在探索TextBlob

我的数据是经过预处理的Twitter数据。这是一个系列,每条推文都经过清理和标记:

    0   [new, leaked, treasury, document, full, sugges...
    1   [tommy, robinson, endorsing, conservative, for...
    2   [thanks, already, watched, catch, tv, morning, ]
    3   [treasury, document, check, today, check, cons...
    4   [utterly, stunning, video, hoped, prayed, woul...
    ... ...
    307370  [trump, disciple, copycat]
    307373  [disgusting]
    307389  [wonder, people, vote, racist, homophobe, like...
    307391  [gary, neville, slam, fuelling, racism, manche...
    307393  [brexit, fault, excuseforeverything]

当我运行textblob时(使用来自Apply textblob in for each row of a dataframe的帮助),我的结果是一列nan值:

    # Create sentiment column using textblob
    # Source: https://stackoverflow.com/questions/43485469/apply-textblob-in-for-each-row-of-a-dataframe

    def sentiment_calc(text):
try:
    return TextBlob(text).sentiment
except:
    return None

    boris_data['sentiment'] = boris_data['text'].apply(sentiment_calc)

         text   sentiment
    0   [new, leaked, treasury, document, full, sugges...   None
    1   [tommy, robinson, endorsing, conservative, for...   None
    2   [thanks, already, watched, catch, tv, morning, ]    None
    3   [treasury, document, check, today, check, cons...   None
    4   [utterly, stunning, video, hoped, prayed, woul...   None
       ...  ... ...
    307370  [trump, disciple, copycat]  None
    307373  [disgusting]    None
    307389  [wonder, people, vote, racist, homophobe, like...   None
    307391  [gary, neville, slam, fuelling, racism, manche...   None
    307393  [brexit, fault, excuseforeverything]    None

Tags: 数据textnonenewforchecktommydocument