ely
ely

Reputation: 77454

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?

Upvotes: 6

Views: 1490

Answers (1)

Chang She
Chang She

Reputation: 16960

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.

Upvotes: 3

Related Questions