# credit to the Stack Overflow user in the source link # df is the pandas DataFrame n = 25 # the number of rows df.groupby(np.arange(len(df))//n).mean()