I have a question regarding Pandas and the correct indexing and replacing of values.
I have 2 DataFrames, df1 and df2, with the same columns (Col1, Col2, Col3 and Col4).
df1 = pd.DataFrame([['A','b','x',1], ['A','b','y',2], ['A','c','z',3], ['B','b','x',4]], columns=['Col1', 'Col2', 'Col3', 'Col4'])
df2 = pd.DataFrame([['A','b','y',0], ['B','b','x',0]], columns=['Col1','Col2','Col3','Col4'])
df1
Col1 Col2 Col3 Col4
0 A b x 1
1 A b y 2
2 A c z 3
3 B b x 4
df2
Col1 Col2 Col3 Col4
0 A b y 0
1 B b x 0
In df1, I would like to replace the values in Col4 in the rows that match the values of the other columns (Col1, Col2 and Col3) in df2 with another value (let's say 100).
The resulting df1 would look like this:
df1
Col1 Col2 Col3 Col4
0 A b x 1
1 A b y 100
2 A c z 3
3 B b x 100
I have tried with something like this:
columns = list(df1.columns)
columns.remove('Col4')
df1.loc[(df1[cols] == df2[cols].values).all(axis=1)]['Col4']=100
But I am getting errors and I am not sure if this is even achieving what I want.