title: Replace a window of size n (above, below) of each 1 in pandas column with 1
body: <p>I have trouble in replacing values above and below of a non-zero number (binary column) with 1.  </p>
  
  <p>I looked online SO posts, but was not able to find a way to tackle this problem.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  data = pd.DataFrame({'fullwindow' : [2, np.NaN, np.NaN, np.NaN, 3, np.NaN, 4, np.NaN, np.NaN, np.NaN, np.NaN, 5], \
    'up' : [1, np.NaN, np.NaN, np.NaN, 1, np.NaN, 2,np.NaN, np.NaN, np.NaN, np.NaN, 2], \
    'down' :[0, np.NaN, np.NaN, np.NaN, 1, np.NaN, 1, np.NaN, np.NaN, np.NaN, np.NaN, 2]})
  
  print data[['up', 'down', 'fullwindow']]
        up  down  fullwindow
   0   1.0   0.0         2.0
   1   NaN   NaN         NaN
   2   NaN   NaN         NaN
   3   NaN   NaN         NaN
   4   1.0   1.0         3.0
   5   NaN   NaN         NaN
   6   2.0   1.0         4.0
   7   NaN   NaN         NaN
   8   NaN   NaN         NaN
   9   NaN   NaN         NaN
   10  NaN   NaN         NaN
   11  2.0   2.0         5.0
  
  dummy = pd.get_dummies(data.fullwindow)
  print dummy
      2.0  3.0  4.0  5.0
  0     1    0    0    0
  1     0    0    0    0
  2     0    0    0    0
  3     0    0    0    0
  4     0    1    0    0
  5     0    0    0    0
  6     0    0    1    0
  7     0    0    0    0
  8     0    0    0    0
  9     0    0    0    0
  10    0    0    0    0  
  11    0    0    0    1
  </code></pre>
  
  <p>In the dummy dataset columns, values above or below 1 will be replaced by 1. For the first column row 0, (2.0), the fullwindow value is 2, 'up' and 'down' values are 1, and 1.  So, below row (row index 1) for column 2.0 will change from 0 to 1.  There is no above row, so it is left as such.  If there are two overlapping ranges, then it is still 1.   For column 4.0, row index 6 is 1.  It has 2 up and 1 down.  So, row index 4, 5, 7 is changed to 1</p>
  
  <p>The expected output for the example</p>
  
  <pre><code>    2.0  3.0  4.0  5.0
  0     1    0    0    0
  1     0    0    0    0
  2     0    0    0    0
  3     0    1    0    0
  4     0    1    1    0
  5     0    1    1    0
  6     0    0    1    0
  7     0    0    1    0
  8     0    0    0    0
  9     0    0    0    1
  10    0    0    0    1  
  11    0    0    0    1
  </code></pre>
  
  <p>For 5.0, row index 11 is 1.  and up is 2, resulting in 9, 10 rows changed to 1</p>