Answers for "How to count a consecutive series of positive or negative values in a column in python"

0

How to count a consecutive series of positive or negative values in a column in python

a = [0,0,1,1,1,0,0,1,0,1,1]
b = [0,0,0,0,0,0,0,0,0,0,0]

for i in range(len(a)):
    if a[i] == 1:
        b[i] = b[i-1] + 1
    else:
        b[i] = 0
Posted by: Guest on June-12-2020

Code answers related to "How to count a consecutive series of positive or negative values in a column in python"

Python Answers by Framework

Browse Popular Code Answers by Language