我有一个类似字典结构的数据帧。我只想把这些值加起来,然后存储到新列中。
Column 1 Desired Output
[{'Apple':3}, 9
{'Mango:2},
{'Peach:4}]
[{'Blue':2}, 3
{'Black':1}]
df['Desired Output'] = [sum(x) for x in df['Column 1']]
df
假设您的Column 1
列确实有字典(而不是看起来像字典的字符串),这应该可以达到目的:
df['Desired Output'] = df["Column 1"].apply(lambda lst: sum(sum(d.values()) for d in lst))