Calculate average of every x rows in a table and create new table
<p>I have a long table of data (~200 rows by 50 columns) and I need to create a code that can calculate the mean values of every two rows and for each column in the table with the final output being a new table of the mean values. This is obviously crazy to do in Excel! I use python3 and I am aware of some similar questions:<a href="https://stackoverflow.com/questions/30379311/fast-way-to-take-average-of-every-n-rows-in-a-npy-array">here</a>, <a href="https://stackoverflow.com/questions/22463609/calculating-an-average-for-every-x-number-of-lines">here</a> and <a href="https://stackoverflow.com/questions/15956309/averaging-over-every-n-elements-of-a-numpy-array">here</a>. But none of these helps as I need some elegant code to work with multiple columns and produces an organised data table. By the way my original datatable has been imported using pandas and is defined as a dataframe but could not find an easy way to do this in pandas. Help is much appreciated.</p>

<p>An example of the table (short version) is:</p>

<pre><code>a   b   c   d
2   50  25  26
4   11  38  44
6   33  16  25
8   37  27  25
10  28  48  32
12  47  35  45
14  8   16  7
16  12  16  30
18  22  39  29
20  9   15  47
</code></pre>

<p>Expected mean table:    </p>

<pre><code>a    b     c     d
3   30.5  31.5  35
7   35    21.5  25
11  37.5  41.5  38.5
15  10    16    18.5
19  15.5  27    38
</code></pre>