我正在尝试合并2个数据帧。它们看起来像这样:
df1 =
e u
0 0.095473 1
1 0.275177 3
2 0.239138 5
3 0.123721 7
4 0.033521 9
5 0.007609 11
6 0.001542 13
df2 =
e u
0 0.239847 5
1 0.145069 7
2 0.047716 9
3 0.011630 11
4 0.002493 13我需要一个数据帧,它包含来自df2的值,但使用df1来提供缺少的值。“index”是“u”。如您所见,df2具有与df1相同的'u‘值,但是缺少一些(df1具有1,3,5,7,9,11,13,而df2具有5,7,9,11,13)。
发布于 2014-08-09 01:45:55
首先将索引设置为u,然后使用df2更新df1
df1 = df1.set_index('u')
df2 = df2.set_index('u')
df1.update(df2)#does update in place does not return a copy
print df1df1的输出现在是....
e
u
1 0.095473
3 0.275177
5 0.239847
7 0.145069
9 0.047716
11 0.011630
13 0.002493https://stackoverflow.com/questions/25207355
复制相似问题