I have a variable (var) with ids I am interested in finding out the position of last occurrence of Z
I have tried to convert it to an array with their positions
zf1=np.where(df2['Var']=="Z")
This will give me the result as
(array([4,5,6,7,8,9,10,11,12,22,23,24,25],dtype=int64),)
My idea was to find the difference of these values and look for -1 - I use the index value of this -1 to add an id next to it
np.diff(zf1)
Var ID
A
B
C
Z
Z
Z
Z
Z
Z
Z
Z
Z 1
X
X
X
X
X
X
B
A
C
Z
Z
Z
Z 2
np.diff is not giving me -1. Is there any alternate method?