【发布时间】:2021-06-05 05:33:29
【问题描述】:
我在 pandas 数据框的列(“结果”)中有这些值。它似乎是列表中的字典。如何创建一个新列“标签”以从此“结果”列中获取值“POSITIVE”?
Orginal column 'results'
df=pd.DataFrame({
'results':[[{'label': 'POSITIVE', 'score': 0.9989271759986877}],
[{'label': 'POSITIVE', 'score': 0.9988722801208496}]
]})
我希望派生列“标签”看起来像这样。
df2=pd.DataFrame({
'results':[[{'label': 'POSITIVE', 'score': 0.9989271759986877}],
[{'label': 'POSITIVE', 'score': 0.9988722801208496}]],
'label': ['POSITIVE','POSITIVE']
})
【问题讨论】:
标签: python list dictionary