I have following 2 dataframe
df_a =
id val
0 A100 11
1 A101 12
2 A102 13
3 A103 14
4 A104 15
df_b =
id loc val
0 A100 12
1 A100 23
2 A100 32
3 A102 21
4 A102 38
5 A102 12
6 A102 18
7 A102 19
.....
desired result:
df_b =
id loc val
0 A100 12 11
1 A100 23 11
2 A100 32 11
3 A102 21 12
4 A102 38 12
5 A102 12 12
6 A102 18 12
7 A102 19 12
.....
When I try to update df_b's 'val' column by df_a's 'val' column like this,
for index, row in df_a.iterrows():
v = row['val']
seq = df_a.loc[df_a['val'] == v]
df_b.loc[df_b['val'] == v, 'val'] = seq['val']
or
df_x = df_b.join(df_a, on=['id'], how='inner', lsuffix='_left', rsuffix='_right')
However I could not solve this... How can I resolve this tricky things?
Thank you