Pandas number of consecutive occurrences in previous rows
问题 I have OHLC data. The candle can be either 'green' (if the close is above open) or 'red' (if the open is above the close). The format is: open close candletype 0 542 543 GREEN 1 543 544 GREEN 2 544 545 GREEN 3 545 546 GREEN 4 546 547 GREEN 5 547 542 RED 6 542 543 GREEN What I would like is to count the number of consecutive green or red candles for n-previous rows. Lets say I want to identify rows preceded by 3 green candles. That the desired output would be: open close candletype pattern 0