Q: Count specific value in pandas rolling window I have a dataframe with thousands rows. One column consists of only 3 values: -1, 0, 1. I would like to count in rolling window (let's say 100) how many times a specific value (let's say 0) occurs. 
How can I do it? I do not see such a method related to the object Rolling and I don't know how to do it by apply.

A: It's pretty simple, I coded up a quick demo. You should get the idea.
Example
# Parameters
# iterable - column
# size - window size (100)

def window(iterable, size=2):
    i = iter(iterable)
    win = []
    for e in range(0, size):
        win.append(next(i))
    yield win
    for e in i:
        win = win[1:] + [e]
        yield win

# Sample data
a = [1, 0, 0, 0, 1, 1]

from collections import Counter

result = []
value = 1 # Value to keep count (-1, 0, 1)

for i in window(a, 2):
    count = Counter(i)[value]
    result.append(count)

# Sample output
print(result)
[1, 0, 0, 1, 2]


A: I guess this will help. I tested this, It works
def cnt(x):
     prev_count = 0
     for i in x:
         if i == 0:
             prev_count+=1
     return prev_count

df['col'].rolling(100,min_periods=1).apply(cnt)

