Given these two data frames:
>>> df1 = pd.DataFrame({'c1':['a','a','b','b'], 'c2':['x','y','x','y'], 'val':0})
>>> df1
c1 c2 val
0 a x 0
1 a y 0
2 b x 0
3 b y 0
>>> df2 = pd.DataFrame({'c1':['a','a','b'], 'c2':['x','y','y'], 'val':[12,31,14]})
>>> df2
c1 c2 val
0 a x 12
1 a y 31
2 b y 14
Is there a function that takes the elements of val
from df2
and puts them in the corresponding indexes of df1
, resulting in:
>>> df1_updated
c1 c2 val
0 a x 12
1 a y 31
2 b x 0
3 b y 14