我有一个有三个索引级别和两列的pandas DataFrame
. 你可以在这里看到它的一部分:
av_intensity std_dev
key1 key2 time
0 0 32000 -0.005203 0.006278
32200 0.005330 0.005221
32400 0.002679 0.005006
32600 -0.000723 0.006145
32800 -0.000317 0.010467
33000 -0.006543 0.007808
33200 -0.004180 0.005070
33400 -0.006275 0.009662
33600 -0.014763 0.006938
33800 -0.029516 0.004710
指数是数字,例如 (0.0, 0, 32000.0)
是一组索引 .
我试图使用 df.ix[ 0.0, :, 32000.0]
或 df.ix[ :, 0, 32000]
进行某种层次索引,但它不起作用 .
Is it because the indices are not integer?
How can I do this kind of hierarchical indexing with this data frame?
1 回答
有关完整说明,请参阅文档中的高级层次结构索引部分:http://pandas.pydata.org/pandas-docs/dev/advanced.html#advanced-indexing-with-hierarchical-index
但基本上,你不能在多索引键中使用这样的切片(
:
) . 你可以做的是创建:
作为slice(None)
:或使用
IndexSlice
便利对象,让你写简单的:
: