Compute daily climatology using pandas python

后端 未结 3 1620
孤街浪徒
孤街浪徒 2020-12-10 17:34

I am trying to use pandas to compute daily climatology. My code is:

import pandas as pd

dates      = pd.date_range(\'1950-01-01\', \'1953-12-31\', freq=\'D\         


        
3条回答
  •  猫巷女王i
    2020-12-10 18:26

    You can groupby the day of the year, and the calculate the mean for these groups:

    cum_data.groupby(cum_data.index.dayofyear).mean()
    

    However, you have the be aware of leap years. This will cause problems with this approach. As alternative, you can also group by the month and the day:

    In [13]: cum_data.groupby([cum_data.index.month, cum_data.index.day]).mean()
    Out[13]:
    1  1     462.25
       2     631.00
       3     615.50
       4     496.00
    ...
    12  28    378.25
        29    427.75
        30    528.50
        31    678.50
    Length: 366, dtype: float64
    

提交回复
热议问题