I have a dataframe and I'd like to apply a function to each 2 columns (or 3, it's variable).
For example with the following DataFrame
, I'd like to apply the mean function to columns 0-1, 2-3, 4-5, ....28-29
d = pd.DataFrame((np.random.randn(360)).reshape(12,30))
0 1 ... 17 18 19 29
0 0.590293 -2.794911 ... 0.772830 -1.389820 -1.696832 ... 0.615549
1 0.115954 2.179996 ... -0.764384 -0.610713 -0.289050 ... -1.130803
2 0.209405 0.381398 ... -0.317797 0.261590 2.502581 ... 1.750126
3 2.828746 0.831299 ... -0.679128 -1.255643 0.245522 ... -0.612011
4 0.625284 1.141448 ... 0.391047 -1.262303 -0.094523 ... -3.643543
5 0.493923 1.601924 ... -0.935102 -2.416869 0.112278 ... -0.001863
6 -1.213347 0.396682 ... 0.671210 0.122041 -1.469256 ... 1.825214
7 0.026695 -0.482887 ... 0.020123 1.151533 -0.440114 ... -1.407276
8 0.235436 0.763454 ... -0.446333 -0.322420 1.067925 ... -0.622363
9 0.668812 0.537556 ... 0.471777 -0.119756 0.098581 ... 0.007390
10 -1.112536 -2.378293 ... 1.047705 -0.812025 0.771080 ... -0.403167
11 -0.709457 -1.598942 ... -0.568418 -2.095332 -1.970319 ... 1.687536