how to format data using Pandas(格式化情感分析结果的数据格式)

how to format data using Pandas (format the data format of the results of sentiment analysis)

我正在使用 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}]

输出结果以列表格式输出

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

试试这个:

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