import numpy as np
from pandas import *
df = DataFrame([3] * 4 + [4] * 4 + [1] * 4, columns=['A'])
df
df.reset_index().groupby('A')['index'].apply(np.array)
Finding consecutive segments in a pandas data frame