I would like to join two dataframes columns by particular columns but I would like some columns to be joined together. I asked something similar here: old question
But now I would need to further split the results in the merge column:
df1 = pd.DataFrame({'List' : ['P111:P666', 'P999', 'P111;P999:P777 ','P555', 'P666:P111;P333'],
'Color' : ['R', 'R', 'B','Y', 'R']})
List Color
0 P111:P666 R
1 P999 R
2 P111;P999:P777 B
3 P555 Y
4 P666:P111;P333 R
df2 = pd.DataFrame({'Cod' : ['P111', 'P222', 'P333', 'P444', 'P555', 'P666', 'P777'],
'Animal' : ['DOG,FROG', 'CAT', 'BUG','SNAKE,DOG', 'CAT,BUG', 'DOG', 'SNAKE']})
Cod Animal
0 P111 DOG,FROG
1 P222 CAT
2 P333 BUG
3 P444 SNAKE,DOG
4 P555 CAT,BUG
5 P666 DOG
6 P777 SNAKE
And I would like:
List Color Animal
0 P111:P666 R DOG,FROG:DOG
1 P999 R -
2 P111;P999:P777 B DOG,FROG;-:SNAKE
3 P555 Y CAT,BUG
4 P666:P111;P333 R DOG:DOG,FROG;BUG
Basically I would like to put ";" and ":" in the "Animal" match column in accordance with the signs in the initial "List" column. If there isn't math I put "-"