johnadem
johnadem

Reputation: 163

How can I split out this list containing a dictionary into separate columns?

The top table is what I have and the bottom is what I want. I'm doing this in a Pandas dataframe. Any help would be appreciated.

enter image description here

enter image description here

Thanks!

Upvotes: 1

Views: 41

Answers (1)

arhr
arhr

Reputation: 1591

It would have been nice if you provided a code snippet for this since we are unable to easily test your case.

The following lines should do the job:

df['label'] = df['sentiment'].apply(lambda x: x[0]['label'])
df['score'] = df['sentiment'].apply(lambda x: x[0]['score'])

Upvotes: 1

Related Questions