I have 3 dataframes in df1
| srno | col1 | col2 | col3 | col4 |
|---|---|---|---|---|
| 1 | a1 | a2 | a3 | |
| 2 | b1 | c2 | c3 | |
| 3 | d1 | b2 | ||
| 4 | e1 | e2 | e3 |
df2
| srno | col1 | col2 | col3 | col4 |
|---|---|---|---|---|
| 1 | a1 | g1 | ||
| 2 | b2 | g2 | ||
| 3 | c2 | c3 | g3 |
df3
| priority | col_combination |
|---|---|
| 1 | col1 |
| 2 | col2,col3 |
I am looking for below output df1
| srno | col1 | col2 | col3 | col4 |
|---|---|---|---|---|
| 1 | a1 | a2 | a3 | g1 |
| 2 | b1 | c2 | c3 | g3 |
| 3 | d1 | b2 | g2 | |
| 4 | e1 | e2 | e3 |
I have tried multiple ways but not able to achieve this, I am new to Python coding, any way to achieve this? Below code I tried it does match and return found/not found but could not yet able to assign df1[col4] = df2[col4] for matching rows.
for i in df3.index:
if "," in df3.loc[i,"col_combination"]:
print("multi column values to handle later")
else:
df1['col4'] = np.where(df1[df3.loc[i, "col_combination"]].isin(df2[df3.loc[i, "col_combination"]]),'found','not found')