更新时间:2023-12-02 21:08:58
是的,看看 combine_first 或更新。例如:
>>> df1['val'] = df2['val'].combine_first(df1['val'])
>>> df1
Out[26]:
c1 c2 val
0 a x 12
1 a y 31
2 b x 14
3 b y 0
编辑:根据c1和c2结合忽略当前索引:
to combine according to c1 and c2 ignoring the current index:
>>> df1['val'] = df2.set_index(['c1','c2'])['val'].combine_first(df1.set_index(['c1','c2'])['val']).values
>> df1
Out[25]:
c1 c2 val
0 a x 12
1 a y 31
2 b x 0
3 b y 14