【发布时间】:2021-01-17 18:39:49
【问题描述】:
我有一个单独的字典列表:
foo = [
{'A': 'a1'}, {'B': 'b1'},{'C': 'c1'},
{'A': 'a2'}, {'B': 'b2'}, {'C': 'c2'},
{'A': 'a3'}, {'B': 'b3'},{'C': 'c3'}
]
我想构建一个这样的DataFrame。
我尝试了这个解决方案来将这个字典列表分组到一个字典中 Combine values of same keys in a list of dicts
bar = {
k: [d.get(k) for d in foo]
for k in set().union(*foo)
}
pd.DataFrame(bar)
但是输出看起来不太好。
有人可以帮忙吗?
【问题讨论】:
标签: python pandas dictionary