相关疑难解决方法(0)

Pandas Concat字典至DataFrame

我有一个现有的数据框,并且正在尝试连接字典,其中字典的长度与数据框的长度不同

>>> df
         A        B        C
0  0.46324  0.32425  0.42194
1  0.10596  0.35910  0.21004
2  0.69209  0.12951  0.50186
3  0.04901  0.31203  0.11035
4  0.43104  0.62413  0.20567
5  0.43412  0.13720  0.11052
6  0.14512  0.10532  0.05310
Run Code Online (Sandbox Code Playgroud)

test = {"One": [0.23413, 0.19235, 0.51221], "Two": [0.01293, 0.12235, 0.63291]}
Run Code Online (Sandbox Code Playgroud)

我想补充testdf,同时改变键"D""C"和我有一个看看

http://pandas.pydata.org/pandas-docs/stable/merging.htmlhttp://pandas.pydata.org/pandas-docs/stable/genic/pandas.concat.html

这表明我应该能够将字典连接到数据框

我试过了:

pd.concat([df, test], axis=1, ignore_index=True, keys=["D", "E"])
pd.concat([df, test], axis=1, ignore_index=True)
Run Code Online (Sandbox Code Playgroud)

但我没有运气,我想要达到的结果是

df
         A        B        C        D        E
0  0.46324  0.32425  0.42194 …
Run Code Online (Sandbox Code Playgroud)

python dictionary pandas

3
推荐指数
2
解决办法
8985
查看次数

标签 统计

dictionary ×1

pandas ×1

python ×1