I wish to merge data frames as fetched via sql under multiple condition.
- df1: First df contains Customer ID, Cluster ID and Customer Zone ID.
- The second df contain complain ID, registration number.
The df1 and df2 are shown below:
df1
Customer ID Cluster ID Customer Zone ID
CUS1001.A CUS1001.X CUS1000
CUS1001.B CUS1001.X CUS1000
CUS1001.C CUS1001.X CUS1000
CUS1001.D CUS1001.X CUS1000
CUS1001.E CUS1001.X CUS1000
CUS2001.A CUS2001.X CUS2000
df2:
Complain ID RegistrationNumber Status
CUS3501.A 99231 open
CUS1001.B 21340 open
CUS1001.X 32100 open
I wish to merge these two data frame with following condition:
if(Complain ID == Customer ID):Merge on Customer ID
Elif(Complain ID == Cluster ID):Merge on Customer ID
Elif (Complain ID == Customer Zone ID):Merge on Customer ID
Else:Merge empty row.
Final result should look like this:
Customer ID Cluster ID Customer Zone ID Complain ID Regi ID Status
CUS1001.A CUS1001.X CUS1000 CUS1001.X 32100 open
CUS1001.B CUS1001.X CUS1000 CUS1001.B 21340 open
CUS1001.C CUS1001.X CUS1000 CUS1001.X 32100 open. . . . . .. . . . . .
CUS2001.A CUS2001.X CUS2000 0 0 0
Please help!