我对情绪分析很陌生,我正在探索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
目前没有回答
相关问题 更多 >
编程相关推荐