I like @EdChum's answer. But reordering the values is disconcerting. It can make both human visual inspections and mechanical comparisons more difficult.
Unfortunately, Python doesn't have an ordered set, which would be the perfect tool here. So:
def unique(items):
"""
Return unique items in a list, in the same order they were
originally.
"""
seen = set()
result = []
for item in items:
if item not in seen:
result.append(item)
seen.add(item)
return result
df.col2 = df.col2.apply(lambda x: '-'.join(unique(x.split('-'))))
An alternative way of creating an ordered set is with OrderedDict:
from collections import OrderedDict
def u2(items):
od = OrderedDict.fromkeys(items)
return list(od.keys())
You can then use u2 instead of unique. Either way, the results are:
col1 col2
0 ben US-Uk
1 Man Uk-NL-DE
2 bee CA-CO-MX