I have a pd.DataFrame which has a column multiindex of the following structure:
a1 a1 a1 a2 a2 a2 a3 a3 a3 ...
b1 b2 b3 b1 b2 b3 b1 b2 b3 ...
row1 values ...
row2
row3
...
I would like to divide each a-group by the last element in its corresponding b3 column. I.e. divide the column a1-b1 by last value in a1-b3, same for a1-b2 and a1-b3 (such that the last element of a1-b3 will actually be 1). for the next group a2, same analogy but dividing its columns by last value in a2-b3. and so on...
I am looking for a simple expression to do this. I have a very cumbersome code where I split up the dataframe into groups that are stored in a dict and then divide each group respectively and merge them back together, but that cant be it, right?
Thanks!
Best, JZ