Resample time series in pandas to a weekly interval

若如初见. 提交于 2019-11-27 02:47:15

问题


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 intervals shorter than a day.


回答1:


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')



回答2:


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



来源:https://stackoverflow.com/questions/14530556/resample-time-series-in-pandas-to-a-weekly-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!