为了账号安全,请及时绑定邮箱和手机立即绑定

循环检索 pandas.core.series.Series 中的情绪分析

循环检索 pandas.core.series.Series 中的情绪分析

白衣染霜花 2021-11-02 16:35:42
我有 47 篇新闻文章要从中提取情绪。它们是 JSON 格式(文章的日期、标题和正文)。我想要的只是使用 TextBlob 获取带有情绪的列表。到目前为止,我正在执行以下操作:import jsonimport pandasfrom textblob import TextBlobappended_data = []for i in range(1,47):    df0 = pandas.DataFrame([json.loads(l) for l in open('News_%d.json' % i)])    appended_data.append(df0)appended_data = pandas.concat(appended_data)doc_set = appended_data.bodydocs_TextBlob = TextBlob(doc_set)for i in docs_TextBlob:    print(docs_TextBlob.sentiment)显然,我收到以下错误:TypeError: The text argument passed to __init__(text) must be a string, not <class 'pandas.core.series.Series'>关于如何使用情绪度量创建列表的任何想法?
查看完整描述

1 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

DataFrame在情绪中创建一个新列:

appended_data['sentiment'] = appended_data.body.apply(lambda body: TextBlob(body).sentiment)


查看完整回答
反对 回复 2021-11-02
  • 1 回答
  • 0 关注
  • 214 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号