I am very close to go insane. I have a dataframe like this:
subject sessionIndex screenIndex index key time
s019 1 3 1 Shift 0.3442
s019 1 3 2 Shift.t 0.1514
s019 1 3 3 h 0.0844
s019 1 3 4 e 0.1127
s019 1 3 5 space 0.1201
s091 3 5 821 h 0.1126
s091 3 5 822 a 0.1425
s091 3 5 823 n 0.0926
s091 3 5 824 d 0.1525
after using:
pivot_table(data,values='time', rows=['subject','sessionIndex','screenIndex','index'], cols=['key'])
I have the following dataframe:
key Shift Shift.t a d ...
subject sessionIndex screenIndex index
s019 1 3 1 0.3442 NaN NaN NaN ...
2 NaN 0.1514 NaN NaN ...
3 NaN NaN NaN NaN ...
4 NaN NaN NaN NaN ...
5 NaN NaN NaN NaN ...
s091 3 5 821 NaN NaN NaN NaN ...
822 NaN NaN 0.1425 NaN ...
823 NaN NaN NaN NaN ...
824 NaN NaN NaN 0.1525 ...
That is great but I got stuck to "unfold" the multiindex so that my dataframe looks like this:
subject sessionIndex screenIndex index Shift Shift.t a d ...
s019 1 3 1 0.3442 NaN NaN NaN ...
s019 1 3 2 NaN 0.1514 NaN NaN ...
s019 1 3 3 NaN NaN NaN NaN ...
s019 1 3 4 NaN NaN NaN NaN ...
s019 1 3 5 NaN NaN NaN NaN ...
s091 3 5 821 NaN NaN NaN NaN ...
s091 3 5 822 NaN NaN 0.1425 NaN ...
s091 3 5 823 NaN NaN NaN NaN ...
s091 3 5 824 NaN NaN NaN 0.1525 ...
I already tried reindexing and index reset. I am fairly new to pandas and python so maybe I am just to stupid. Please let me know what I am missing here, Thx.