pandas count consecutive values

Solutions on MaxInterview for pandas count consecutive values by the best coders in the world

showing results for - "pandas count consecutive values"
Samuel
04 Apr 2017
1why the obsession with the ultra-pythonic way of doing things? readability + efficiency trumps "leet hackerz style."
2
3I'd just do it like so:
4
5a = [0,0,1,1,1,0,0,1,0,1,1]
6b = [0,0,0,0,0,0,0,0,0,0,0]
7
8for i in range(len(a)):
9    if a[i] == 1:
10        b[i] = b[i-1] + 1
11    else:
12        b[i] = 0