【问题标题】:how to format data using Pandas (format the data format of the results of sentiment analysis)如何使用 Pandas 格式化数据(格式化情感分析结果的数据格式)
【发布时间】:2021-10-22 01:34:45
【问题描述】:

我正在使用 BERT 进行情绪分析。 我想将结果转换为 DataFrame 格式,但我不知道如何。 如果有人知道,请告诉我。

相关网页如下 https://huggingface.co/transformers/main_classes/pipelines.html

>>> pipe = pipeline ("text-classification")
>>> pipe (["This restaurant is awesome", "This restaurant is aweful"])
[{'label':'POSITIVE','score': 0.9998743534088135},
  {'label':'NEGATIVE','score': 0.9996669292449951}]

输出结果以列表形式输出。

因此,我想将其转换为如下所示的数据框格式。我应该做什么样的处理?

【问题讨论】:

  • DataFrame 构造函数有什么问题? pd.DataFrame([{'label':'POSITIVE','score': 0.9998743534088135}, {'label':'NEGATIVE','score': 0.9996669292449951}])

标签: python pandas dataframe sentiment-analysis


【解决方案1】:

试试这个:

sentiment = pipe (["This restaurant is awesome", "This restaurant is aweful"])
df = pd.DataFrame(sentiment)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-09
    • 2014-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2019-12-05
    • 1970-01-01
    相关资源
    最近更新 更多