I have a dataset for example:
df = pd.DataFrame({'x':[1,5,7,8], 'y':['12,4', '1,6,7', '8,3,2', '1']})
I want to split column y, order it, and change the comma (',') into dash ('-') like this:
x y
0 1 4-12
1 5 1-6-7
2 7 2-3-8
3 8 1
I've tried using apply but it shows TypeError: can only join an iterable
df['y'] = df['y'].str.split(',')
df['y'] = df['y'].apply(lambda x : '-'.join(x.sort()))
What is wrong with my code?