Compare One Portion Of Dataframe To Another With Multi-index
I have a dataframe with a 3-level MultiIndex: >>> np.random.seed(0) >>> df = pd.DataFrame(np.random.randint(10, size=(18, 2)), index=pd.Mult
Solution 1:
Cross-section xs
would probably be a good option here:
df.sub(
df.xs('maybe', level=1)
).swaplevel().reindex(df.index)
Output:
A B
bool ans count
True yes one-3-8
two 2-3
three 02noone-5-3
two 1-2
three 0-1
maybe one00
two 00
three 00False yes one6-2
two -38
three 56noone20
two -82
three 2-3
maybe one00
two 00
three 00
Post a Comment for "Compare One Portion Of Dataframe To Another With Multi-index"