In [1]:
import pandas as pd
import numpy as np
In [8]:
rng = pd.date_range('1/1/2011', periods=72, freq='H')
rng[1:4]
Out[8]:
In [7]:
ts = pd.Series(list(range(len(rng))), index=rng)
ts.head()
Out[7]:
In [10]:
converted = ts.asfreq('45Min', method='ffill')
converted.head(10)
Out[10]:
In [11]:
ts.shape
Out[11]:
In [12]:
converted.shape
Out[12]:
In [14]:
converted2 = ts.asfreq('3H')
converted2.head()
Out[14]:
In [17]:
#mean of 0 and 1, 2 and 3 etc
ts.resample('2H').mean()[0:10]
Out[17]:
In [30]:
#resampling events in irregular time series
irreq_ts = ts[ list( np.random.choice( a = list( range( len(ts))), size=10, replace=False ))]
irreq_ts
Out[30]:
In [34]:
irreq_ts = irreq_ts.sort_index()
irreq_ts
Out[34]:
In [36]:
irreq_ts.resample('H').fillna( method='ffill', limit=5)
Out[36]:
In [38]:
irreq_ts.resample('H').count()
Out[38]:
In [ ]: