python pandas多级索引获取特定值

问题描述

我每小时都有一个熊猫值分组数据框

2020.05.05 17:00:00  cpu_usage_specint        4.354603
                     phys_iops             3075.779680
                     total_memory         13843.480000
2020.05.05 18:00:00  cpu_usage_specint        3.670237
                     phys_iops             3403.007340
                                              ...     
2020.05.11 22:00:00  phys_iops            30459.577340
                     total_memory         28851.025000
2020.05.11 23:00:00  cpu_usage_specint        1.903852
                     phys_iops             8161.811320
                     total_memory         28827.575000

the index is a MultiIndex([('2020.05.05 17:00:00','cpu_usage_specint'),('2020.05.05 17:00:00','phys_iops'),'total_memory'),('2020.05.05 18:00:00',('2020.05.05 19:00:00',('2020.05.05 20:00:00',...
            ('2020.05.11 20:00:00',('2020.05.11 21:00:00',('2020.05.11 22:00:00',('2020.05.11 23:00:00','total_memory')],

例如,我想要每个小时的每个指标的特定值

for date in metrics_pivot_df.index.get_level_values('date').unique():
    print('this is the date',date)

这给了我日期,但是我也想说total_memory的值,所以我可以做一些测试,例如> =等,但是我不知道如何获取值?我已经尝试引用“ mertic”列,但是当我尝试执行查询时返回true / false

非常感谢

解决方法

我看不见树木的树林

for date in metrics_pivot_df.index.get_level_values('date').unique():
    print('this is a specific date',date,metrics_pivot_df.loc[date,'cpu_usage_specint'])

解决了