I have a dataframe (df) which has a year per row:
Jan Feb Mar Apr ... Aug Sep Oct Nov Dec
2021 0.852144 0.406946 0.067136 0.686585 ... 0.839023 0.803384 0.506883 0.829171 0.214810
2022 0.442388 0.296960 0.751213 0.690898 ... 0.701342 0.924836 0.534601 0.601725 0.673403
That I would like to reformat so there is one row with all month/years in sequential order (where the index for each row if mmm yyyy format) so it would look like:
0
Jan 2021 0.852144
Feb 2021 0.406945
Mar 2021 0.067136
Apr 2021 0.686585
... ...
Aug 2022 0.701342
Sep 2022 0.924836
Oct 2022 0.534601
Nov 2022 0.601725
Dec 2022 0.673403
I have used:
df = df.unstack().to_frame().T.sort_index(0,1).T
but I can't get the index to format correctly for all rows(would like mmm yyyy for each row index - currently only returning the month for alternate rows)
0
Jan 2021 0.852144
2022 0.442388
Feb 2021 0.406946
2022 0.296960
Mar 2021 0.067136
2022 0.751213
Apr 2021 0.686585
2022 0.690898
... ...
Aug 2021 0.839023
2022 0.701342
Sep 2021 0.803384
2022 0.924836
Oct 2021 0.506883
2022 0.534601
Nov 2021 0.829171
2022 0.601725
Dec 2021 0.214810
2022 0.673403