2

I'm trying to use Pandas to create a time index in Python with entries corresponding to a recurring payday. Specifically, I'd like to have the index correspond to the first and third Friday of the month. Can somebody please give a code snippet demonstrating this?

Something like:

import pandas as pd
idx = pd.date_range("2016-10-10", periods=26, freq=<offset here?>)
themaestro
  • 13,750
  • 20
  • 56
  • 75
  • I'm not sure pandas has this built-in functionality. You will likely have to use `dateutil` to build a sequence of datetime objects. See: http://stackoverflow.com/questions/28680896/how-can-i-get-the-3rd-friday-of-a-month-in-python – juanpa.arrivillaga Oct 10 '16 at 22:12

1 Answers1

2

try this:

In [6]: pd.date_range("2016-10-10", periods=26, freq='WOM-1FRI').union(pd.date_range("2016-10-10", periods=26, freq='WOM-3FRI'))
Out[6]:
DatetimeIndex(['2016-10-21', '2016-11-04', '2016-11-18', '2016-12-02', '2016-12-16', '2017-01-06', '2017-01-20', '2017-02-03', '2017-02-17',
 '2017-03-03', '2017-03-17', '2017-04-07', '2017-04-21',
               '2017-05-05', '2017-05-19', '2017-06-02', '2017-06-16', '2017-07-07', '2017-07-21', '2017-08-04', '2017-08-18', '2017-09-01',
 '2017-09-15', '2017-10-06', '2017-10-20', '2017-11-03',
               '2017-11-17', '2017-12-01', '2017-12-15', '2018-01-05', '2018-01-19', '2018-02-02', '2018-02-16', '2018-03-02', '2018-03-16',
 '2018-04-06', '2018-04-20', '2018-05-04', '2018-05-18',
               '2018-06-01', '2018-06-15', '2018-07-06', '2018-07-20', '2018-08-03', '2018-08-17', '2018-09-07', '2018-09-21', '2018-10-05',
 '2018-10-19', '2018-11-02', '2018-11-16', '2018-12-07'],
              dtype='datetime64[ns]', freq=None)
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419