I have the following dataframe "A":
1 2 3
Date
1971-01-04 46 47 9
1971-01-05 95 58 6
1971-01-06 30 52 85
and the following empty dataframe "B", with the same row indices as "A", and multi-index columns:
1
level_1 1 2 3
Date
1971-01-04
1971-01-05
1971-01-06
I'm trying to fill "B" using either of the two levels of the column headers to identify the column of "A" to get the data from.
So, when using the first column headers level [1, 1, 1], this is the expected output:
1971-01-04 46 46 46
1971-01-05 95 95 95
1971-01-06 30 30 30
and this is the expected output when using the second column headers level [1, 2, 3]:
1971-01-04 46 47 9
1971-01-05 95 58 6
1971-01-06 30 52 85
I could iterate through columns but I guess there's a better way. Thanks