简体   繁体   English

如何将此包含字典的列表拆分为单独的列?

[英]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.我在 Pandas dataframe 中执行此操作。 Any help would be appreciated.任何帮助,将不胜感激。

在此处输入图像描述

在此处输入图像描述

Thanks!谢谢!

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'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字典列表分成单独的列? - How do I separate the dictionary list into separate columns? 将嵌套的 json/字典从 Pandas dataframe 拆分为单独的列 - Split out nested json/dictionary from Pandas dataframe into separate columns 我如何在元组列表和列表之外有数据框的单独列 - How can I have separate columns of a dataframe out of list of tuples and a list 如何将包含列表的 python 字典拆分为单独的字典 - How to split a python dictionary containing lists into separate dictionaries 如何将字符串字典转换为字典并拆分为单独的列 - How to Convert String Dictionary to Dictionary and the split into separate columns 将字典列拆分为单独的列,融化数据框 - Split list of dictionary column to separate columns, melting the dataframe 在 Python 中,如何将包含名称和地址的字符串数据集拆分为单独的列。 - In Python, how can you split a dataset of strings containing name and address into separate columns.? 如何将具有多个文本列表值的python字典拆分为具有相同值的键的单独字典? - How can I split a python dictionary with multiple text-list values to have separate dictionaries of keys that have the same values? 如何将这本字典在一列中拆分为他们自己的列? - How can I split this dictionary in a column in to their own columns? 拆分包含列表作为值的字典 - Split a dictionary containing list as values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM