I have a multi-index column dataframe that also has date. I would like the columns to be as rows.
For example:
| A | A | B | B |
| X | Y | X | Y | Date |
| 1 | 2 | 3 | 4 | May-08 |
And I need it to be
| Start | End | Value | Date |
| A | X | 1 | May-08 |
| A | Y | 2 | May-08 |
etc.
Sorry for the wonky formatting. When I tried to add code, the submission form freaked out and I couldn't figure out how to make it work.
Please let me know if you have any questions and I will answer them to the best of my ability
Assuming this input:
You can
meltwith a bit of pre-processing of the MultiIndex to remove NaNs/None (that don'tmeltwell), and post-processing of the resulting Index to remove the tuple:If the empty levels in the MultiIndex are
'', you can skip the pre-processing.Output: