Question: This is probably a very basic question but I haven't been able to find the answer so here goes...

Question:

Is there an say way to sort the values alphabetically while also removing any duplicate instances?

Here's what I have:

```
data = ['Car | Book | Apple','','Book | Car | Apple | Apple']
df = pd.DataFrame(data,columns=['Labels']
print(df)

    Labels
0   Car | Book | Apple
1   
2   Book | Car | Apple | Apple

```

Desired Output:

```
    Labels
0   Apple | Book | Car
1   
2   Apple | Book | Car

```

Thanks!

Answer: 
`str.join` after `str.split`

```
df=df.replace({' ':''},regex=True)
df.Labels.str.split('|').apply(set).str.join('|')
Out[339]: 
0    Apple|Book|Car
1                  
2    Apple|Book|Car
Name: Labels, dtype: object

```

Base on the comment adding `sorted`

```
df.Labels.str.split('|').apply(lambda x : sorted(set(x),reverse=False)).str.join(' | ')

```
One way is to use `pd.Series.map` with `sorted` & `set` after splitting by `|`:

```
import pandas as pd

data = ['Car | Book | Apple','','Book | Car | Apple | Apple']
df = pd.DataFrame(data,columns=['Labels'])

df['Labels'] = df['Labels'].map(lambda x: ' | '.join(sorted(set(x.split(' | ')))))

#                Labels
# 0  Apple | Book | Car
# 1                    
# 2  Apple | Book | Car

```