I have a three sets of code (code1, code 2 and code 3) having alphanumeric objects. All the codes are separated by delimiter (;) , and the codes are related based on sequence like A123 of code 1 is related to A of code 2 and A445 of code 3, and so on. Code 3 has some codes duplicated or repeated.
My desired output is to get the concatenated "code 4" where code 1 and code 2 are concatenated based on either of these two conditions
a) if the corresponding code in code 3 has no repeated value
b) if the corresponding code in code 3 has repeated value, then the position corresponding to the position of last repeated value in code 3 needs to be used for concatenating code 1 and code 2 (like B678 R4 because A445 is repeated twice in code 3, and the 4th position of A445 needs to be considered for concatenating code 1 and code 2)
Let me know if any logic can be used to get the output. Thanks in advance!
Python script for dataframe df is
df11 = pd.DataFrame({"code1": ["A123; A321; B478; B678; C567", "A321; A821; B448; B698; C577"], "code2": ["A; B5; N5; R4; H5", "A3; B; N; R7; H2"],"code3": ["A445; A323; A323; A445; A659", "A328; A328; A621; A442; A621"]}, index=[0, 1], )
Desired output along with the input codes should look like this
