I want to resample a TimeSeries in daily (exactly 24 hours) frequence starting at a certain hour.
Like:
index = date_range(datetime(2012,1,1,17), freq='H', periods=60)
ts = Series(data=[1]*60, index=index)
ts.resample(rule='D', how='sum', closed='left', label='left')
Result i get:
2012-01-01 7
2012-01-02 24
2012-01-03 24
2012-01-04 5
Freq: D
Result i wish:
2012-01-01 17:00:00 24
2012-01-02 17:00:00 24
2012-01-03 17:00:00 12
Freq: D
Some weeks ago you could pass '24H'
to the freq
argument and it worked totally fine.
But now it combines '24H'
to '1D'
.
Was I using a bug with '24H'
which is fixed now?
And how can i get the wished result in a efficient and pythonic (or pandas) way back?
versions:
Resample Hourly Data to Daily Data To simplify your plot which has a lot of data points due to the hourly records, you can aggregate the data for each day using the . resample() method. To aggregate or temporal resample the data for a time period, you can take all of the values for each day and summarize them.
Resample time-series data. Convenience method for frequency conversion and resampling of time series. The object must have a datetime-like index ( DatetimeIndex , PeriodIndex , or TimedeltaIndex ), or the caller must pass the label of a datetime-like series/index to the on / level keyword parameter.
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.
Resample has an base
argument which covers this case:
ts.resample(rule='24H', closed='left', label='left', base=17).sum()
Output:
2012-01-01 17:00:00 24
2012-01-02 17:00:00 24
2012-01-03 17:00:00 12
Freq: 24H
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With