I need help with an issue I have concerning the creation of a sequence.
The sequence should be based on the value of
ID_PROJET_test field that contains a bool which indicates whether we should increment or not.
if ID_PROJET_test = False then increment
if ID_PROJET_test = True then do not increment
For instance, if ID_PROJET_test contains the following Series: s1 = [0,0,1,0,1,0]
ID_PROJET should be equal to : [1,2,2,3,3,4]
If ID_PROJET_test contains the following Series: s2 = [0,0,0,1,1,1,0,0]
ID_PROJET should be equal to : [1,2,3,3,3,3,4,5]
I can do it easily with a for loop :
compteur = 1
for i in range(len(df)):
if df['ID_PROJET_test']==True:
df.ID_PROJET[i] = compteur
else:
compteur += 1
df.ID_PROJET[i] = compteur
However, I have around 1.8M records and it is much too slow. Any idea on how to do it?