I'm trying to write a program to get some specific data. I got a column that can have integer numbers (negative, positive and zeros), I wanted to count the consecutive zeros before getting a negative or positive. I succesfully got (with help) to code that. But I get a column adding the previous number and cumulating the sum, but I only need the biggest number before finding a zero.
I got this code to check cumulative sum for the zero values, this count restarts when finds a zero.
a = df['Amperaje'].shift().eq(0)
b = a.cumsum()
df['DT_Count'] = b.sub(b.mask(a).ffill().fillna(0))
print (df)
With this for example if my base column has: df['Amperaje']= [0,0,-53,-25,6,0,0,0,5] I get df['DT_Count']= [1,2,3,0,0,0,0,1,2,3,4]
But I only want to have the 3 then the 4, the rest of the list 0.