如何在熊猫中获取分层索引系列中值的索引

时间:2019-09-19 08:15:34

标签: python pandas multi-index

假设我有一个名为test的数据结构:

12    2     80.0
      4      2.0
      6      8.0
      7     15.0
      8     26.0
            ... 
1095  12    59.0
      15     2.0
1098  8      6.0
      13    16.0
1128  13    32.0
Length: 62, dtype: float

其类型为:pandas.core.series.Series

现在,我需要的只是右侧列中值的实际坐标。即

>>>test[0]
80.0

然后,我想知道如何实际访问此索引(以及所有其他值),最好是使其可以成对返回:

>>>test[0].method_which_returns_the_desired_indices()
(12,2)

当然,其余的也一样

>>>test[2].method_which_returns_the_desired_indices()
(12,6)

该如何处理?如果有帮助,test系列是使用stack()从另一个熊猫数据框构造的。

1 个答案:

答案 0 :(得分:1)

带有整数的切片索引:

print (test.index[0])
(12, 2)

print (test.index[2])
(12, 6)