首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将vader sentiment脚本的输出转换为csv的数据帧

如何将vader sentiment脚本的输出转换为csv的数据帧
EN

Stack Overflow用户
提问于 2020-04-16 05:23:37
回答 1查看 361关注 0票数 0

我希望将我的输出转换为情绪评分的数据帧格式

我有一个输出数据帧:

代码语言:javascript
运行
复制
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
for transcript in transcript:
    vs = analyzer.polarity_scores(transcript)
    print("{:-<65} {}".format(transcript, str(vs)))


thank you for calling my name is Britney and her the pleasure speaking with %HESITATION yes this is clearer Craddock and I just want to let you know that %HESITATION my little pumpkin passed away oh oh okay let me %HESITATION get that set up here for you then okay can you just verify for me your mailing address eleven oh five west street was in California nine five six nine five  {'neg': 0.0, 'neu': 0.823, 'pos': 0.177, 'compound': 0.9001}
thank you %HESITATION and then %HESITATION you said pumpkin passed away if you don't mind me asking when did pumpkin patch %HESITATION in the last week and of last week okay so %HESITATION what we will do is we will cancel it effective  {'neg': 0.041, 'neu': 0.804, 'pos': 0.155, 'compound': 0.6705}
what is last week this ------------------------------------------ {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
so did you want to cancel it effective the tense so or the end of last week as in like it was Friday or Saturday %HESITATION %HESITATION %HESITATION %HESITATION the tent it was around the time okay so we will cancel it effective %HESITATION the ten just to you know make sure if there was any coverage dates if you have to submit anything we don't have to worry about that getting in the way and I do just have to read a quick verification to you okay okay so as you requested your plan for pumpkin will be canceled effective at five you worry tenth of two thousand twenty is the refund is due with the change it will be processed within seven business days and it also gives me a confirmation number did you want to write that down or just save it here on file  {'neg': 0.038, 'neu': 0.768, 'pos': 0.193, 'compound': 0.9676}
%HESITATION ----------------------------------------------------- {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
please leave it there on file all right and then did you have additional questions while I had you Clara  {'neg': 0.059, 'neu': 0.829, 'pos': 0.112, 'compound': 0.2732}
%HESITATION no no I don't I just want to let you people know that it is a pumpkin is gone and %HESITATION %HESITATION squeaker message %HESITATION %HESITATION I said if you have any anything you have questions about or you need to talk about something you feel free to call okay Clara okay okay good day okay thank you bye thank you bye bye  {'neg': 0.077, 'neu': 0.667, 'pos': 0.256, 'compound': 0.9038}

如您所见,所有的输出都在一起。我希望输出的格式是显示句子,然后将相关分数显示在列neg、中性、正和复合中,就像数据帧一样,而不是连续的句子。如何转换输出?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-16 06:47:50

代码语言:javascript
运行
复制
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
text = ['She is pretty', 'He is ugly']
 scores = []
for txt in text:
    vs = analyzer.polarity_scores(txt)
    scores.append(vs)
data = pd.DataFrame(text, columns= ['Text'])
data2 = pd.DataFrame(scores)
final_dataset= pd.concat([data,data2], axis=1)

我希望这段代码能帮助你!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61238847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档