如何使用 Pandas 按分组数据的分类索引 select

How to select by categorical index of grouped data using Pandas

我正在尝试 select 来自分组分类索引的数据,但无法按组 select。

这些数据是使用 pd.cut 在 60 个 bin 中收集的。最终目标是 select 索引范围然后绘制数据 - 但是我不能 select数据。

例如 - 我想 select 切片 (0,60] 和 (60,120] 但我无法切片。非常感谢任何帮助。

当前数据帧数据:

谢谢

pd.cut 只是创建字符串值,因此您可以直接使用 .ix 在列表中给出它们,或者只是使用 .iloc:

进行位置索引
In [7]: df
Out[7]:
            0    1
1
(-1, 0]  0.00  0.0
(0, 1]   0.01  1.0
(1, 2]   0.02  2.0
(2, 4]   0.03  3.0

In [8]: df.ix[['(0, 1]', '(1, 2]']]
Out[8]:
           0    1
1
(0, 1]  0.01  1.0
(1, 2]  0.02  2.0

In [9]: df.iloc[1:3]
Out[9]:
           0    1
1
(0, 1]  0.01  1.0
(1, 2]  0.02  2.0