I am working with some time series data that is set up in the following way:
The indx
column starts at 1 and goes to around 434-460 (some series are longer than others) and then starts back at 1 again. What I would like to do is to transpose this so my dataframe looks like this where each row contains a couple lists for the time series:
Time MAG TAU
[time1, time2, ..., timen] [MAG1, MAG2, ..., MAGn] (this is the value stored every time
... ... indx=1)
... ... ...
Edit
I have now tried to use pd.pivot()
rather than melt()
and this as as close as I've gotten. Using:
pd.pivot_table(df, index=['indx'], values=['MAG', 'time'], aggfunc=lambda x:list(x))
However, this just makes a really long list grouped by indx
: