我有一个像下面这样的系列。
In [53]: aStack
Out[53]:
Age_cat S0102_gender
_1 Male 167.047843
Female 211.292291
All 378.340134
_2 Male 132.055426
Female 171.780338
All 303.835764
All Male 299.103269
Female 383.072629
All 682.175898
dtype: float64
In [54]:
我想将系列转换为看起来像这样的东西。
In [53]: aStack
Out[53]:
Age_cat S0102_gender
_1 Male 167.047843
_1 Female 211.292291
_2 All 378.340134
_2 Male 132.055426
_2 Female 171.780338
_2 All 303.835764
All Male 299.103269
All Female 383.072629
All All 682.175898
我有一个元组列表。
combos
Out[54]:
[('_1', 'Male'),
('_1', 'Female'),
('_1', 'All'),
('_2', 'Male'),
('_2', 'Female'),
('_2', 'All'),
('All', 'Male'),
('All', 'Female'),
('All', 'All')]
根据文档。如果我跑,
aStack.reindex(combos)
我应该得到那个输出。但是,当我运行指令时,我得到的输出与我的输入相同。我错过了什么?
您的起始系列已经有一个 MultiIndex,它不会在每行上打印最外层(0 级)索引值。要查看每行中向下重复的每个索引值(出于显示目的等),请尝试aStack.reset_index()
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句