for ton of dates, need compute next business day, account holidays.
currently, i'm using code below, i've pasted ipython notebook:
import pandas pd pandas.tseries.holiday import usfederalholidaycalendar cal = usfederalholidaycalendar() bday_offset = lambda n: pd.datetools.offsets.custombusinessday(n, calendar=cal) mydate = pd.to_datetime("12/24/2014") %timeit with_holiday = mydate + bday_offset(1) %timeit without_holiday = mydate + pd.datetools.offsets.bday(1) on computer, with_holiday line runs in ~12 milliseconds; , without_holiday line runs in ~15 microseconds.
is there way make bday_offset function faster?
i think way implementing via lambda slowing down. consider method (taken more or less straight documentaion )
from pandas.tseries.offsets import custombusinessday bday_us = custombusinessday(calendar=usfederalholidaycalendar()) mydate + bday_us out[13]: timestamp('2014-12-26 00:00:00') the first part slow, need once. second part fast though.
%timeit bday_us = custombusinessday(calendar=usfederalholidaycalendar()) 10 loops, best of 3: 66.5 ms per loop %timeit mydate + bday_us 10000 loops, best of 3: 44 µs per loop to apples apples, here other timings on machine:
%timeit with_holiday = mydate + bday_offset(1) 10 loops, best of 3: 23.1 ms per loop %timeit without_holiday = mydate + pd.datetools.offsets.bday(1) 10000 loops, best of 3: 36.6 µs per loop
Comments
Post a Comment