I have a data like below:
# df
Col1 Col2 Col3 Col4
AAA
AAA AAA BBB
AAA CCC
I want to concat them without duplicates.
Col1 Col2 Col3 Col4 COMBINE
AAA AAA
AAA AAA BBB AAA/BBB
AAA CCC AAA/CCC
The code I tried:
df["COMBINE"] = df[df.filter(regex='^Col',axis=1).columns].apply(lambda x: '/'.join(pd.unique(x)),axis=1)
But I got:
Col1 Col2 Col3 Col4 COMBINE
AAA AAA/
AAA AAA BBB AAA/BBB/
AAA CCC AAA/CCC/
.str.strip()would work for this data.