Resampling with custom periods

后端 未结 2 538
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 18:02

Is there a \'cookbook\' way of resampling a DataFrame with (semi)irregular periods?

I have a dataset at a daily interval and want it to resample to what sometimes (in s

2条回答
  •  你的背包
    2021-02-05 18:33

    Using HYRY's data and solution up to the computation of the d variable, we can also do the following in pandas 0.11-dev or later (regardless of numpy version):

    In [18]: from datetime import timedelta
    
    In [23]: pd.Series([ timedelta(int(i)) for i in d ])
    Out[23]: 
    0             00:00:00
    1     1 days, 00:00:00
    2     2 days, 00:00:00
    3     3 days, 00:00:00
    4     4 days, 00:00:00
    5     5 days, 00:00:00
    6     6 days, 00:00:00
    7     7 days, 00:00:00
    8     8 days, 00:00:00
    9     9 days, 00:00:00
    10            00:00:00
    
    47    6 days, 00:00:00
    48    7 days, 00:00:00
    49    8 days, 00:00:00
    50    9 days, 00:00:00
    Length: 51, dtype: timedelta64[ns]
    

    The date is constructed similary to above

    date = pd.Series(df.index) - pd.Series([ timedelta(int(i)) for i in d ])
    df.groupby(date.values).mean()
    

提交回复
热议问题