class Group:
    start = 0
last_type = 0

def four_group(self, x):
    if x < Group.last_type:
        Group.start += 1
groupNum = Group.start
Group.last_type = x
return groupNum
df = pd.read_csv('chart.csv')
zzz = Group()
df['TempGroup'] = df.type.apply(lambda x: zzz.four_group(x))
How to separate rows of dataframe based on dynamic conditions using Python