串联并填充熊猫中缺少的列

我有df个,如下:

df1:

   id city district      date  value
0   1   bj       ft  2019/1/1      1
1   2   bj       ft  2019/1/1      5
2   3   sh       hp  2019/1/1      9
3   4   sh       hp  2019/1/1     13
4   5   sh       hp  2019/1/1     17

df2

   id      date  value
0   3  2019/2/1      1
1   4  2019/2/1      5
2   5  2019/2/1      9
3   6  2019/2/1     13
4   7  2019/2/1     17

我需要根据df连接id,并在city的{​​{1}}中填充districtdf2。预期的应该是这样的:

df1

到目前为止,用 id city district date value 0 1 bj ft 2019/1/1 1 1 2 bj ft 2019/1/1 5 2 3 sh hp 2019/1/1 9 3 4 sh hp 2019/1/1 13 4 5 sh hp 2019/1/1 17 5 3 sh hp 2019/2/1 1 6 4 sh hp 2019/2/1 5 7 5 sh hp 2019/2/1 9 8 6 NaN NaN 2019/2/1 13 9 7 NaN NaN 2019/2/1 17 生成的结果是这样的:

pd.concat([df1,df2],axis=0)

谢谢!

nihao_123456 回答:串联并填充熊猫中缺少的列

React-Native列的左侧加入DataFrame.merge

React-Native-Web
本文链接:https://www.f2er.com/3161749.html

大家都在问