Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resample time series in pandas to a weekly interval

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.

like image 693
2daaa Avatar asked Jan 25 '13 21:01

2daaa


People also ask

How do I resample data in pandas?

Resample Pandas time-series data. The resample() function is used to resample time-series data. Convenience method for frequency conversion and resampling of time series. Object must have a datetime-like index (DatetimeIndex, PeriodIndex, or TimedeltaIndex), or pass datetime-like values to the on or level keyword.

How do you convert daily data into weekly data in Python?

Method 1: using Python for-loops. Function new_case_count() takes in DataFrame object, iterates over it and converts indexes, which are dates in string format, to Pandas Datetime format. Based on the date's day of the week, each week's new cases count is calculated and stored in a list.


1 Answers

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') 
like image 113
Andy Hayden Avatar answered Oct 10 '22 07:10

Andy Hayden