在连续值组中切片pandas数据帧

hel*_*ker 5 python slice pandas

我有一个数据框,其中包含最终"跳过"的连续值的部分(即,增加超过1).我想分割数据帧,类似于groupby函数(仅用于show的字母索引):

    A
a   1
b   2
c   3
d   6
e   7
f   8
g   11
h   12
i   13

# would return

a   1
b   2
c   3
-----
d   6
e   7
f   8
-----
g   11
h   12
i   13
Run Code Online (Sandbox Code Playgroud)

ZJS*_*ZJS 11

速度答案略有改进......

for k,g in df.groupby(df['A'] - np.arange(df.shape[0])):
    print g
Run Code Online (Sandbox Code Playgroud)