将同键词典连接到pandas中的数据框中

Ant*_*nko 8 python dictionary pandas

如何用DataFrame两个或多个具有共同键的词典创建一个熊猫?也就是说,转换

d1 = {'a': 1}
d2 = {'a': 3}
...
Run Code Online (Sandbox Code Playgroud)

进入一个数据框,其中包含列['d1', 'd2', ...],行索引"a"和相应字典确定的值?

unu*_*tbu 7

import pandas as pd
d1 = {'a': 1, 'b':2}
d2 = {'a': 3, 'b':5}

df = pd.DataFrame([d1, d2]).T
df.columns = ['d{}'.format(i) for i, col in enumerate(df, 1)]
Run Code Online (Sandbox Code Playgroud)

产量

In [40]: df
Out[40]: 
   d1  d2
a   1   3
b   2   5
Run Code Online (Sandbox Code Playgroud)