I have the following Dataframe
df = pd.DataFrame({'Category': {0: 'onboarding segment-confirmation-unexpected-input origin',
1: 'onboarding segment-confirmation-unexpected-input view',
2: 'product-availability cpf-request-unexpected-input origin',
3: 'product-availability postalcode-validation-true-unexpected-input origin',
4: 'product-availability postalcode-validation-true-unexpected-input view'},
'UserId': {0: 9090, 1: 4545, 2: 3266, 3: 2894, 4: 2772}})
What I want to do is to formulate a flag that checks if the string part that is different than the word "view" or "origin". Is equal to the previous value, if so maintain the flag if not increase the flag value.
Wanted result
df = pd.DataFrame({'Category': {0: 'onboarding segment-confirmation-unexpected-input origin',
1: 'onboarding segment-confirmation-unexpected-input view',
2: 'product-availability cpf-request-unexpected-input origin',
3: 'product-availability postalcode-validation-true-unexpected-input origin',
4: 'product-availability postalcode-validation-true-unexpected-input view'},
'UserId': {0: 9090, 1: 4545, 2: 3266, 3: 2894, 4: 2772},
'Flag':{0:'Flag_1',1:'Flag_1',2:'Flag_2',3:'Flag_3',4:'Flag_3'}})
What would be the way to do this? I tried to slice it and formulating a groupby but I am having a little difficulty on the increasing part.