I would like to convert this:
W X Y Z tdate tdim stringdate
0 0.335737 -0.380237 -0.473996 -0.000448 2015-11-20 c 2015-11-20
1 -0.092511 1.149210 -0.834495 -0.585204 2015-05-25 c 2015-05-25
2 1.425946 1.293430 -0.545142 0.287451 2015-12-17 b 2015-12-17
3 -0.199412 1.011220 0.400355 0.470182 2015-03-21 c 2015-03-21
4 2.265234 -0.314174 0.684593 -1.360268 2015-12-23 b 2015-12-23
5 -0.192996 0.150177 -0.684978 0.464223 2015-11-19 b 2015-11-19
6 -1.089473 -1.375843 -0.901250 -0.775122 2015-07-25 c 2015-07-25
7 -0.572807 -2.484145 -2.339342 -0.263439 2015-05-31 a 2015-05-31
To this (with actual data instead of zero placeholder):
date 2015-11-20 2015-05-25 2015-12-17 2015-03-21 2015-12-23 \
metrics W X W X W X W X W X
tdim
a 0 0 0 0 0 0 0 0 0 0
b 0 0 0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 0 0 0 0
date 2015-11-19 2015-07-25 2015-05-31
metrics W X W X W X
tdim
a 0 0 0 0 0 0
b 0 0 0 0 0 0
c 0 0 0 0 0 0
I've skimmed over Pandas MultiIndexes and created one myself. That's how I arrived at the latter DataFrame, but I did not see an example in that documentation where he reindexes an existing DataFrame to have multiple column levels.
I have looked at this Pandas: add a column to a multiindex column dataframe and pandas dataframe select columns in multiindex. These are insightful but not specifically helpful for this case.
I have not attempted a brute force solution (i.e. manually populating data using loops).
I am using Python 2.7.10 and pandas 0.16.1.