df = pd.DataFrame({'index': [0, 1, 2, 3, 4, 5], 'f_key': [1, 2, 1, 2, 3, 1],
    'values': ['red', 'blue', 'green', 'yellow', 'orange', 'violet']})
df['duplicate_num'] = df.sort_values('index').groupby('f_key').cumcount() + 1
Number duplicates sequentially in Pandas DataFrame