Find Average of Every Three Columns in Pandas dataframe
问题 I am new to Python and Pandas. I have a panda dataframe with monthly columns ranging from 2000 (2000-01) to 2016 (2016-06). I want to find the average of every three months and assign it to a new quarterly column (2000q1). I know I can do the following: df['2000q1'] = df[['2000-01', '2000-02', '2000-03']].mean(axis=1) df['2000q2'] = df[['2000-04', '2000-05', '2000-06']].mean(axis=1) . . . df['2016-02'] = df[['2016-04', '2016-05', '2016-06']].mean(axis=1) But, this is very tedious. I