I have stumbled upon this thread:
Monthly Averages Using Daily Data Using Python Pandas
which has answered most of my question. The remaining part is, how can I line up the results with the original data accordingly, like this:
1979 1 1 3
1979 1 2 3
1979 1 3 3
1979 1 4 3
1979 1 5 3
1979 1 6 3
1979 1 7 4
1979 1 8 5
1979 1 9 7
1979 1 10 8
1979 1 11 16
1979 1 12 16
1979 1 13 16
1979 1 14 18
1979 1 15 18
1979 1 16 18
1979 1 17 18
1979 1 18 20
1979 1 19 20
1979 1 20 20
1979 1 21 20
1979 1 22 20
1979 1 23 18
1979 1 24 18
1979 1 25 18
1979 1 26 18
1979 1 27 18
1979 1 28 18
1979 1 29 18
1979 1 30 18
1979 1 31 19 13.709677
1979 2 1 19
1979 2 2 19
1979 2 3 19
1979 2 4 19
1979 2 5 19
1979 2 6 22
1979 2 7 24
1979 2 8 27
1979 2 9 29
1979 2 10 32
1979 2 11 32
1979 2 12 32
1979 2 13 32
1979 2 14 33
1979 2 15 33
1979 2 16 33
1979 2 17 34
1979 2 18 36
1979 2 19 36
1979 2 20 36
1979 2 21 36
1979 2 22 36
1979 2 23 36
1979 2 24 31
1979 2 25 29
1979 2 26 27
1979 2 27 27
1979 2 28 27 29.107143
Thanks in advance