I want to create a new column that appends a sequential numeric suffix to matching values.
If I begin with the following...
d = {'item': ['A', 'A', 'B', 'C', 'C', 'A'],
'year': [2019, 2019, 2019, 2019, 2020, 2020]}
df0 = pd.DataFrame(d)
item year
0 A 2019
1 A 2019
2 B 2019
3 C 2019
4 C 2020
5 A 2020
I want this intermediate step,
item item_number year
0 A 1 2019
1 A 2 2019
2 B 1 2019
3 C 1 2019
4 C 2 2020
5 A 3 2020
then this final form.
numbered_item item year
0 A 1 A 2019
1 A 2 A 2019
2 B 1 B 2019
3 C 1 C 2019
4 C 2 C 2020
5 A 3 A 2020