Bin pandas dataframe by every X rows

In Python 2 use:

>>> df.groupby(df.index / 3).mean()
   col1
0   2.0
1   0.5

Leave a Comment