How to broadcast to multi-index

I have two pandas arrays, A and B, which are the result of groupby operations. A has a two-level multi-index, consisting of both quantiles and dates. B just has an index for the date.

Between the two of them, the date indices are the same (in each quantile index for A).

Is there a standard pandas function or idiom for β€œtranslating” B, so that it will have an extra level for its multi-index, which corresponds to the first level of multi-index A?

+4
source share
1 answer

If you just want to do simple arithmetic, 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 indexes.

0
source

All Articles