Conditional replacement of row's values in pandas DataFrame,df['SEQ'] = df.sort_values(by='START').groupby('ID').cumcount() + 1