In pandas documentation one can read "Under the hood, these frequency strings are being translated into an instance of pandas DateOffset" when speaking of freq string such as "W" or "W-SUN".
Then, how can I get an instance of a DateOffset given a string ? Ultimately want to configure my program with frequency as string (say "W-SUN"), but internally want to do something like
offset = Week(weekday=0)
if d1-3*offset<d2:
pass
but defining offset
from string.
Thanks
You could use the to_offset
function for this, although this is a rather internal pandas function (so possibly no backwards compatibility guaranteed). Some examples:
In [12]: pd.tseries.frequencies.to_offset('4Min')
Out[12]: <4 * Minutes>
In [13]: pd.tseries.frequencies.to_offset('W-SUN')
Out[13]: <Week: weekday=6>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With