[SciPy-user] assignment of hours of day in time series

matt mattknox_ca@hotmail....
Sun Jan 6 21:36:42 CST 2008


> table 4:      
> desired report output     
> date  hour_of_day value
> 1-Feb-2004    1:00    247
> 1-Feb-2004    2:00    889
> 1-Feb-2004    3:00    914
> 1-Feb-2004    4:00    292
> 1-Feb-2004    5:00    183
> 1-Feb-2004    6:00    251
> 1-Feb-2004    7:00    953
> 1-Feb-2004    8:00    156
> 1-Feb-2004    9:00    991
> 1-Feb-2004    10:00   557
> 1-Feb-2004    11:00   581
> 1-Feb-2004    12:00   354
> 1-Feb-2004    13:00   485
> 1-Feb-2004    14:00   655
> 1-Feb-2004    15:00   862
> 1-Feb-2004    16:00   399
> 1-Feb-2004    17:00   598
> 1-Feb-2004    18:00   744
> 1-Feb-2004    19:00   445
> 1-Feb-2004    20:00   374
> 1-Feb-2004    21:00   168
> 1-Feb-2004    22:00   995
> 1-Feb-2004    23:00   943
> 1-Feb-2004    24:00   326
> 


Hi Tim,

sorry for not getting back to you earlier. You are correct in that I did miss
the posting earlier. Since the time "24:00" doesn't actually exist (as far as I
am aware anyway), you will have to rely on somewhat of a hack to get your
desired output. Try this:

>>> import timeseries as ts
>>> series = ts.time_series(range(400, 430), start_date=ts.now('hourly'))
>>> hours = ts.time_series(series.hour + 1, dates=series.dates)
>>> hour_fmtfunc = lambda x : '%i:00' % x
ts.Report(hours, series, datefmt='%d-%b-%Y', delim='  ',
          fmtfunc=[hour_fmtfunc, None])()
06-Jan-2008  23:00  400
06-Jan-2008  24:00  401
07-Jan-2008   1:00  402
07-Jan-2008   2:00  403
07-Jan-2008   3:00  404
07-Jan-2008   4:00  405
07-Jan-2008   5:00  406
07-Jan-2008   6:00  407
07-Jan-2008   7:00  408
07-Jan-2008   8:00  409
07-Jan-2008   9:00  410
07-Jan-2008  10:00  411
07-Jan-2008  11:00  412
07-Jan-2008  12:00  413
07-Jan-2008  13:00  414
07-Jan-2008  14:00  415
07-Jan-2008  15:00  416
07-Jan-2008  16:00  417
07-Jan-2008  17:00  418
07-Jan-2008  18:00  419
07-Jan-2008  19:00  420
07-Jan-2008  20:00  421
07-Jan-2008  21:00  422
07-Jan-2008  22:00  423
07-Jan-2008  23:00  424
07-Jan-2008  24:00  425
08-Jan-2008   1:00  426
08-Jan-2008   2:00  427
08-Jan-2008   3:00  428
08-Jan-2008   4:00  429

=================================

basically add one to the "hour" property of the series to get your desired
output.

- Matt



More information about the SciPy-user mailing list