I have 4 csv files with different correlations (and different number of rows) and I am trying to create a new one with all correlations:
DF1: |Var1|Var2|Corr1|
DF2: |Var1|Var2|Corr2|
Objective:
|Var1|Var2|Corr1|Corr2|
(EDIT:
DF1: DF2:
Var1 Var2 Corr Var1 Var2 Corr2
a b 2 a b 3
a s 1 a z 4
c d 0 c d 2
Spected Out:
DF1:
Var1 Var2 Corr Corr2
a b 2 3
a s 1 NaN
c d 0 2
a z NaN 4
Finish edit)
The condition is if Var1 and Var2 are the same, add Corr2 value in new column (It would be also good to add new rows if they are new correlations in DF2)
I have this but is not working:
corr=[]
for row in DF1['Var1']:
if DF1['Var2'] == DF2['Var2'] : corr.append(DF2["Corr2"])
##else: add DF2["Var1]["Var2"]["Corr2"]
DF1["Corr2"]=corr
print(DF1)
Any idea to create this condition? Thank you