Skip to content Skip to sidebar Skip to footer

Keep 24h For Each Day When Resampling `pandas` `series` (from Daily To Hourly)

I have a pandas Series with a (tz-localized) DateTimeIndex with one value per day: tmpr Out[38]: 2018-01-01 00:00:00+01:00 1.810 2018-01-02 00:00:00+01:00 2.405 2018-01-03 0

Solution 1:

Since your data is daily, you can do just create new timestamps and reindex:

new_timestamps = pd.date_range(tmpr.index[0], 
                          tmpr.index[-1]+pd.to_timedelta('23H'),
                          freq='H')

tmpr.reindex(new_timestamps).ffill()

Output (for the first half of your sample data):

2018-01-01 00:00:00+01:001.8102018-01-01 01:00:00+01:001.8102018-01-01 02:00:00+01:001.8102018-01-01 03:00:00+01:001.8102018-01-01 04:00:00+01:001.810...2018-01-05 19:00:00+01:000.5452018-01-05 20:00:00+01:000.5452018-01-05 21:00:00+01:000.5452018-01-05 22:00:00+01:000.5452018-01-05 23:00:00+01:000.545Freq:H,Name:tmpr,Length:120,dtype:float64

Post a Comment for "Keep 24h For Each Day When Resampling `pandas` `series` (from Daily To Hourly)"