简体   繁体   English

访问 python pivot 表中的子索引级别

[英]Accessing sub-index levels in python pivot table

I am facing an issue regarding pivot tables in python with multi index.我面临一个关于 python 中具有多索引的 pivot 表的问题。 For several indexes, I try to access the different items of the last index in order to freeze some values.对于几个索引,我尝试访问最后一个索引的不同项目以冻结一些值。 For example in the screenshot, for each date, if its equal to a certain value (24/12/2020) I look for each ref in it (Ref0, Ref1, etc).例如在屏幕截图中,对于每个日期,如果它等于某个值(2020 年 12 月 24 日),我会查找其中的每个参考(参考 0、参考 1 等)。 If the Ref1 is in it, I freeze the values of 23/12/2020 for the 24/12/2020.如果 Ref1 在其中,我将 23/12/2020 的值冻结为 24/12/2020。 So in the Ex1 I don't do anything but for Ex2, all the values (and columns) of 23/12/2020 will be the same as the one for 24/12/2020.因此,在 Ex1 中,除了 Ex2,我什么都不做,2020 年 12 月 23 日的所有值(和列)将与 2020 年 12 月 24 日的值相同。 I tried to loop on Value1 for accessing the corresponding indexes (with index.get_level_values()), but I don't see how I can know every items in Ref for each value.我试图在 Value1 上循环以访问相应的索引(使用 index.get_level_values()),但我不知道如何知道每个值的 Ref 中的每个项目。 Can you please help me?你能帮我么?

ps: their is only one unique date for each index of Index 3. So once I have done what I want, I move to the net Index 3 ps:对于索引 3 的每个索引,它们只是一个唯一日期。所以一旦我完成了我想要的操作,我就会移动到网络索引 3

Thanks a lot.非常感谢。

[Python_Multilevel_PivotTable] [Python_Multilevel_PivotTable]1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM