Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to broadcast to a multiindex

I have two pandas arrays, A and B, that result from groupby operations. A has a 2-level multi-index consisting of both quantile and date. B just has an index for date.

Between the two of them, the date indices match up (within each quantile index for A).

Is there a standard Pandas function or idiom to "broadcast" B such that it will have an extra level to its multi-index that matches the first multi-index level of A?

like image 716
ely Avatar asked Aug 28 '12 20:08

ely


1 Answers

If you just want to do simple arithmetic operations, I think something like A.div(B, level='date') should work.

Alternatively, you can do something like B.reindex(A.index, level='date') to manually match the indices.

like image 134
Chang She Avatar answered Nov 08 '22 23:11

Chang She