Hi I'm trying to reshape a data frame in a certain way.
this is the data frame I have,
des1 des2 des3 interval1 interval2 interval3
value
aaa a b c ##1 ##2 ##3
bbb d e f ##4 ##5 ##6
ccc g h i ##7 ##8 ##9
des1 corresponds with interval1 and so on. interval columns have a range of dates and des columns have descriptions.
I'd like to reshape the dataframe such that it looks like this:
des interval
value
aaa a ##1
aaa b ##2
aaa c ##3
bbb d ##4
bbb e ##5
bbb f ##6
ccc g ##7
ccc h ##8
ccc i ##9
How would I go about doing this? I'm a little familar with .stack() but I haven't been able to get exactly what I wanted.
Thank you for your help. feel free to post references.
I think the solution provided by CT Zhu is very genius. But you also can reshape this step by step (maybe this is the common way).
This might be a shorter approach:
Or preserve the 1,2,3 info:
This is just a
.melt
, docs are here