0

I am trying to check when a client appears in my dataframe to do some logic with other results. However, I am unable to number when the customer appears. I've gotten the first and last time it appears, I just can't get it in the intervals between the first and last time. Could you please help me? Here is an example table, I want column C as the result.

Date    Customer    Appear
01/01/2021  A   1
01/01/2021  B   1
01/01/2021  C   1
01/02/2021  A   2
01/02/2021  B   2
01/02/2021  C   2
01/03/2021  A   3
01/03/2021  B   3
01/03/2021  C   3
01/04/2021  A   4
01/04/2021  B   4
01/05/2021  A   5
01/05/2021  B   5
01/06/2021  A   6

enter image description here

haraujo
  • 33
  • 7

1 Answers1

1

You can try with groupby with cumcount

df['new'] = df.groupby('Customer').cumcount()+1
Out[202]: 
0     1
1     1
2     1
3     2
4     2
5     2
6     3
7     3
8     3
9     4
10    4
11    5
12    5
13    6
dtype: int64
BENY
  • 317,841
  • 20
  • 164
  • 234