I m not sure if this has been answered before. But my requirement is that I have a dataframe like this:
df1:
A B
I1 I2
x11 x12 a11 b11
x12 x22 a21 b21
Note that this has multiindex of [I1, I2] and columns [A, B]
and then another dataframe like this:
df2:
I1 I2
0 x11 x12
1 y11 y12
This has columns [I1, I2] which is the same as multiindex of df1.
Now what I would like to create is two dataframes like below:
df3 which has rows for which the index in df1 matches to that of column values in df2
A B
a11 b11
df4 with the remaining i.e.
A B
a21 b21
I know how to do this using iterrows() but it is not efficient. Looking for a vectorized solution. Thanks.