简体   繁体   中英

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

I am doing sentiment analysis using BERT. I want to convert the result to DataFrame format, but I don't know how. If anyone knows, please let me know.

The related web pages are as followshttps://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}]

The output result is output in list format.

Therefore, I want to convert it to the data frame format as shown below. What kind of processing should I do?

在此处输入图片说明

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM