I'm trying to merge two string columns and I wish to get rid of 'others'
if the counter value is a 'non-others' value - like 'apple' + 'others' = 'apple'
but 'others' + 'others' = 'others'
. I managed the 2nd condition but how can I accommodate the two conditions on the merge?
data = {'fruit1':["organge", "apple", "organge", "organge", "others"],
'fruit2':["apple", "others", "organge", "watermelon", "others"]}
df = pd.DataFrame(data)
df["together"] = df["fruit1"] + ' ' + df["fruit2"]
df["together"] = df["together"].apply(lambda x: ' '.join(pd.unique(x.split())))
fruit1 fruit2 together
0 organge apple organge apple
1 apple others apple others
2 organge organge organge
3 organge watermelon organge watermelon
4 others others others
Expected output:
fruit1 fruit2 together
0 organge apple organge apple
1 apple others apple
2 organge organge organge
3 organge watermelon organge watermelon
4 others others others