title: Replacing more than n consecutive values in Pandas DataFrame column
body: <p>Supposing I have the following DataFrame <code>df</code></p>
  
  <pre><code>df = pd.DataFrame({"a" : [1,2,2,2,2,2,2,2,2,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5], "b" : [3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,7,7], "c" : [4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,1,2,2,2,2,2,2,2,2,3,3]})
  </code></pre>
  
  <p>And I wish to replace number 4's which repeat more than 10 times in a row, in any column (there could be hundreds of columns), with 10 4's and the remainder 5's. </p>
  
  <p><strong>So for example, 12 consecutive 4's would be replaced with ten 4's and two 5's.</strong> </p>
  
  <p>How would I achieve this with Pandas?</p>
  
  <p>I'd like to apply a lambda, but I don't know how to look back enough rows, and it would have to start from the end and move through forward, or it would break the sequence of values. Each lookup would have to look at the preceding 10 rows to see if they are all equal to 4, and if so, set the current value to 5.</p>
  
  <p>No idea how to go about it though!</p>