Resample time series in pandas to a weekly interval

前端 未结 3 1231
庸人自扰
庸人自扰 2020-12-03 10:46

How do I resample a time series in pandas to a weekly frequency where the weeks start on an arbitrary day? I see that there\'s an optional keyword base but it only works for

相关标签:
3条回答
  • 2020-12-03 11:05

    Neither Andy Haydens nor denfromufas answer worked for me but that did: df.resample('W', label='left', loffset=pd.DateOffset(days=1))

    as described in that answer: https://stackoverflow.com/a/46712821/1743551

    0 讨论(0)
  • 2020-12-03 11:06

    You will be much safer with resampling based on days and then slicing every 7th day, e.g:

    ts.resample('D').interpolate()[::7]
    

    See the underlying problem with other approaches in this open pandas issue on github:

    https://github.com/pandas-dev/pandas/issues/16381

    0 讨论(0)
  • 2020-12-03 11:21

    You can pass anchored offsets to resample, among other options they cover this case.

    For example the weekly frequency from Monday:

    ts.resample('W-MON')
    
    0 讨论(0)
提交回复
热议问题