【发布时间】: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