I have the following data in an Excel sheet and I want to read it as a multiindex dataframe:
Y1 Y1 Y2 Y2
B H1 H2 H1 H2
1 80 72 79.2 84.744
2 240 216 237.6 254.232
3 40 36 39.6 42.372
4 160 144 158.4 169.488
5 240 216 237.6 254.232
6 0 0 0 0
I am reading it as:
DATA = pd.read_excel('data.xlsx',sheet_name=None)
since I am reading other sheets too.
Question 1:
This data is not read as multi-index data. How do I make it read it as multi-index? Or maybe I should read it as a dataframe and then convert it to multi-index? Current result of reading as dataframe
DATA['Load']
Y1 Y1.1 Y2 Y2.1
bus H1 H2 H1 H2
1 80 72 79.2 84.744
2 240 216 237.6 254.232
3 40 36 39.6 42.372
4 160 144 158.4 169.488
5 240 216 237.6 254.232
6 0 0 0 0
Question 2 and probably the more fundamental question:
How do I deal with multi-indexing when one or more of the indexes are on the columns side? In this example, I want to access the data by specifying B, Y, H. I know how to work with multi-index when they are all as index, but can't get the hang of it when the indexes are on the columns.
Thank you very much for your help :)
PS:
Another sheet may look like the following:
from to x ratea
1 2 0.4 10
1 4 0.6 80
1 5 0.2 10
2 3 0.2 10
2 4 0.4 10
2 6 0.3 10
3 5 0.2 10
4 6 0.3 10
where I will set from and to as set (set_index(['from','to']) to get a multi-index dataframe.