更新时间:2023-11-29 19:20:22
尝试一下. reset_index
删除最后一个级别,因此乘以它们是相同的
Try this. reset_index
removes the last level, so they are the same when you multiply
In [25]: x = data_3levels.reset_index(level=2,drop=True)*data_2levels
由于您想要原始索引(并且形状未更改),因此可以正常工作.
Since you want the original index (and the shape hasn't changed), this works.
In [26]: x.index=data_3levels.index
In [27]: x
Out[27]:
l1 l2 l3
0 100 1000 2
1001 2
1002 2
1 101 1001 3
dtype: int64