I know it seem similar to other question, but I can't find the solution on the link someone marked this question as duplicate. Maybe someone can explain. So here we are. I have a dataset (df
) of time series as follow:
date symbol close
09/01/2018 ACA 132,1
10/01/2018 ACA 134,4
...
28/04/2013 BA 22,12
...
21/01/2016 DIL 180,01
...
The idea was to convert it as this:
date ACA BA DIL
28/04/2013 NaN 22,12 NaN
...
21/01/2016 NaN 23 180,01
...
...
...
10/01/2018 134,4 32,2 181,3
As suggested by Troy D It can be used df.unstack()
as follow:
df = df.set_index(['date', 'symbol'])
df = df.unstack()
df = df['close']
The problem is that I sometimes have multiple time series with the same "symbol". Therefore, if I do nothing this error appears:
ValueError: Index contains duplicate entries, cannot reshape
Since I don't want them to be merged, how could I rename them following, for example, by 2,3, and so on to make easier to unstack()
?