I am new to Python Pandas and am looking for advice on how to proceed with a problem. I have a large dataframe and I would like to sum the columns of the rows by 50 at a time to form new rows with one column being the mean of a time series. I worded that poorly, but here is an example:
Say I have this dataframe, where A is an increasing time series:
A B C D
0 1 23 45 21
1 2 34 23 65
2 3 56 84 35
3 4 67 20 70
I'd like to "collapse" the rows by 2 rows so that they look like this, with columns B, C, and D summed and column A being the mean:
A B C D
0 1.5 57 68 86
1 3.5 123 104 110
I have looked into using cut() and groupby(), but neither of these seem to do what I want.
Edit: For anybody also looking for this, I found it easiest to treat it as a resampling based on the index values. The solution for my particular problem was this:
df = df.groupby(df.index // 50).sum()
Then I found the mean by dividing the column I needed to by 50.