I have a Dataframe like this
oper_status
2012-01-01 00:26:54.250 0
2012-01-01 12:11:54.250 1
2012-01-01 13:57:54.250 2
2012-01-02 00:16:54.250 0
2012-01-02 14:26:54.250 1
2012-01-02 17:20:54.250 0
2012-01-04 08:21:54.250 0
2012-01-04 15:34:54.250 1
2012-01-04 19:45:54.250 0
2012-01-05 01:00:54.250 0
2012-01-05 12:46:54.250 1
2012-01-05 20:27:54.250 2
(...) (...)
and I want to count how many times every month I have consecutive values with this pattern: 0,1,2. I tried looping on the rows with iterrows() but it's very slow since I have a big dataset. I also thought about using "diff" but I can't figure out a simple way to do it. Thanks
EDIT: The expected output is like this
count
time
2012-03-31 244
2012-04-30 65
2012-05-31 167
2012-06-30 33
2012-07-31 187
... ...
2013-05-31 113
2013-06-30 168
2013-07-31 294
2013-08-31 178
2013-09-30 65