I have two dataframes A and B as follows :
A
col1 col2 col3
A B V1
A B V2
A C V1
A E V2
B
Col1 Col2 Value1 Value2
A B nan nan
A D nan nan
A C nan nan
A G nan nan
A E nan nan
I want to update the columns Value1 and Value2 in dataframe B on the basis of dataframe A, as if the combination of Col1 and Col 2 of A exists in B it will update columns Value1 Value2 i.e. the values from col3 in dataframe A.
I want the output as :
Col1 Col2 Value1 Value2
A B V1 V2
A D nan nan
A C V1 nan
A G nan nan
A E nan V2
I tried the following code in python :
def update_b():
for x in b.index:
for y in a.index:
if ((a["col1"][y] == b["col1"][x]) & (a["col2"][y] == b["col2"][x])):
if (a["col3"][y] == "V1"):
b["value1"][x] = "V1"
else:
b["value2"][x] = "V2"
update_b()
but it gives me an error
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Value2? and notValue1?