I have 2 data frames as below:
df1={"group":["A","B"],
"unit":["U1","U2"],
"char1":["C1","C2"],
"char2":["Large","Medium"],
"char3":["","R"]
}
df1=pd.DataFrame.from_dict(df1)
and
df2={"char1":["C1","C1","C1","C1","C2","C2","C2","C3","C3"],
"char2":["Large","Large","Large","Large","Medium","Medium","Medium","Medium","Large"],
"char3":["U","U","U","R","R","R","U","R","R"],
"result":[113,114,115,116,818,819,1101,1102,1103]}
df2=pd.DataFrame.from_dict(df2)
I want to filter df2 with the values of df1 columns(char1,char2,char3). Finally, for each group_unit pair in df1, I want to assign filtered results from df2.
The desired output would look like the following:
output={"group":["A","A","A","A","B","B"],
"unit" :["U1","U1","U1","U1","U2","U2"],
"result":[113,114,115,116,818,819]}
output=pd.DataFrame.from_dict(output)
I have tried using "isin" and some other stuff but couldn't manage to get there. I appreciate with any kind of soft coding solution.