for index, value in t.items():
    if index == 0:
        res.set_value(index, 0)
else:
    if value < t.loc[index - 1]:
        previous_df_no += 1
res.set_value(index, previous_df_no)
return res
df['temp'] = separate_df(df.type)
How to separate rows of dataframe based on dynamic conditions using Python