I want to create this table in python:
x1 target
1 1
1 1
23 2
32 3
1 1
2 2
2 3
4 4
1 1
This is easy to solve in Excel,

but I don't know, how can I do this in pyton: First target row is "1", then:
target = if ['x1']=1 then ['target']=1 else ['target']=['target'].shift(1)+1
I tried this code, but doesn't worked:
import pandas as pd
df=pd.read_excel('/x1.xlsx')
df.loc[df.index == 0, 'target'] = 1
df.loc[df['x1']==1, 'target'] = 1
df.loc[df['x1'] != 1, 'target'] = df['target'].shift(1)+1
Anyone know how to solve this? Thanks in advance!