python - Mask timeseries outside business hours -


hello have hourly timeseries mask if timeseries index outside business hours.

i can achieve want business day data not hourly data

import datetime import pandas pd import numpy np pandas.tseries.offsets import *  st = datetime.datetime(2013, 1, 1) ed = datetime.datetime(2013, 2, 1) myrange = pd.date_range(st, ed, freq='h') ts = pd.series(np.random.randn(len(myrange)), index=myrange) ts.asfreq(bday()).asfreq(day()) 

i have tried generating bday date range , changing freq hourly doesn't work.

newrange = pd.date_range(datetime.datetime(2013, 1, 1), datetime.datetime(2013, 1, 1), freq='b')  #but adding doesn't work .asfreq(hour()) ts[ts.index.isin(newrange)].asfreq(hour()) #of course gives 1 value on day 

thanks

to restrict times business days use:

ts = ts.ix[ts.index.map(bday())] 

and indexer_between_time restrict between business hours:

ts = ts.ix[ts.index.indexer_between_time(time(7), time(18))] 

to restrict business days within business hours (apply these in either order).


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -