title: How to align 3 dataframes with some threshold in python?
body: <p>I have some x &amp; y columns in a dataframe such as below:</p>
  <pre><code>          X-1    X-1_y         X-2    X-2_y         X-3    X-3_y
  0   411.726266  1387.29  437.404307  3755.08  437.273585  3360.85
  1   437.692665   677.39  448.557534  1460.70  448.760155   981.45
  2   448.596937  2276.35  481.550490     0.00  481.566018     0.00
  3   481.634531     0.00  486.966310     0.00  487.208899     0.00
  4   486.971163     0.00  492.578155     0.00  492.446192     0.00
  5   492.505388     0.00  500.000000   608.22  500.153040     0.00
  6   500.030500   810.45  508.218825     0.00  508.315935     0.00
  7   508.106596     0.00  513.579177     0.00  513.620953  9582.45
  8   513.424161     0.00  515.308245     0.00  515.175867     0.00
  9   535.131828     0.00  534.346333     0.00  534.985459     0.00
  10  551.779516  3124.92  551.712654  2226.94  551.680943  2522.73
  11  559.050425  1081.89  559.084859   984.05  559.087271  1600.48
  12  562.108257  3532.11  562.253910  3686.94  562.234223  4495.73
  13  591.436797     0.00  590.659433     0.00  591.396752     0.00
  </code></pre>
  <p>and I would like to align all 3 X columns and merge it to 1 X column. if the numbers in X columns are too close to each other (i.e +- 1) get a avg of the three if available but if the numbers are not close to each other, append a new row, so the final result would be a new dataframe like this :</p>
  <pre><code>         avg X    X-1_y    X-2_y    X-3_y
  0   411.726266  1387.29     0.00     0.00
  1   437.456852   677.39  3755.08  3360.85
  2   448.638209  2276.35  1460.70   981.45
  3   481.583680     0.00     0.00     0.00
  4   487.048791     0.00     0.00     0.00
  5   492.509912     0.00     0.00     0.00
  6   500.061180   810.45   608.22     0.00
  7   508.213785     0.00     0.00     0.00
  8   513.541430     0.00     0.00  9582.45
  9   515.242056     0.00     0.00     0.00
  10  534.821206     0.00     0.00     0.00
  11  551.724371  3124.92  2226.94  2522.73
  12  559.074185  1081.89   984.05  1600.48
  13  562.198797  3532.11  3686.94  4495.73
  14  591.164327     0.00     0.00     0.00
  </code></pre>
  <p>example of how the result is created:</p>
  <p>if the numbers in a row of X are +- 1 then get a avg, if all 3 are not within +-1, then append three new rows but if 1 is not within the other two then append 2 rows (1 is the new off value and 2nd is the avg of the other 2 that are within +-1). for example , on first row of data,</p>
  <pre><code>        X-1    X-1_y         X-2    X-2_y         X-3    X-3_y
  0   411.726266  1387.29  437.404307  3755.08  437.273585  3360.85
  1   437.692665   677.39  448.557534  1460.70  448.760155   981.45
  </code></pre>
  <p>X1(411.72) is not within +-1 of the X2(437.4) and X3(437.2) so it will append a new line in the result but  X2(437.4) and X3(437.2) are within +-1 of each other and also within +-1 of the 2nd row of the X1(437.692) so append a avg of the 3 in the next line avg of (X1_row2 , X2_row1 , X3_row1)
  results will be</p>
  <pre><code>         avg X    X-1_y    X-2_y    X-3_y
  0   411.726266  1387.29     0.00     0.00
  1   437.456852   677.39  3755.08  3360.85
  </code></pre>
  <p>thanks in advance</p>