I have a time series of hourly values and I am trying to derive some basic statistics on a weekly/monthly basis.
If we use the following abstract dataframe, were each column is time-series:
rng = pd.date_range('1/1/2016', periods=2400, freq='H')
df = pd.DataFrame(np.random.randn(len(rng), 4), columns=list('ABCD'), index=rng)
print df[:5]
returns:
A B C D
2016-01-01 00:00:00 1.521581 0.102335 0.796271 0.317046
2016-01-01 01:00:00 -0.369221 -0.179821 -1.340149 -0.347298
2016-01-01 02:00:00 0.750247 0.698579 0.440716 0.362159
2016-01-01 03:00:00 -0.465073 1.783315 1.165954 0.142973
2016-01-01 04:00:00 1.995332 1.230331 -0.135243 1.189431
I can call:
r = df.resample('W-MON')
and then use: r.min()
, r.mean()
, r.max()
, which all work fine. For instance print r.min()[:5]
returns:
A B C D
2016-01-04 -2.676778 -2.450659 -2.401721 -3.209390
2016-01-11 -2.710066 -2.372032 -2.864887 -2.387026
2016-01-18 -2.984805 -2.527528 -3.414003 -2.616434
2016-01-25 -2.625299 -2.947864 -2.642569 -2.262959
2016-02-01 -2.100062 -2.568878 -3.008864 -2.315566
However, if I try to calculate percentiles, using the quantile formula, i.e. r.quantile(0.95)
, I get one value for each column
A 0.090502
B 0.136594
C 0.058720
D 0.125131
Is there a way to combine the grouping / resampling using quantiles as arguments?
Thanks