I have a pandas dataframe
df = pd.DataFrame({'user':[1,2,2,3], 'date':['2023-04-12', '2023-04-13', '2023-04-15','2023-04-18'],
'variable':['x1','x1','x2','x1'], 'sth':['xx','yy','yy','zz']})
user date variable sth
0 1 2023-04-12 x1 xx
1 2 2023-04-13 x1 yy
2 2 2023-04-15 x2 yy
3 3 2023-04-18 x1 zz
and would like to stack it such that I receive this dataframe
user sth x1 x2
0 1 xx 2023-04-12 NaN
1 2 yy 2023-04-13 2023-04-15
2 3 zz 2023-04-18 NaN
How do I need to do this?