1

I need to generate an array of dates at specific intervals. for example every 3 sunday of the month:

[2019-02-17, 2019-03-17, 2019-04-21]

Is it possible to do this using standard pandas functions? For example, specifying some particular freq field in the pd.date_range method or using pd.Dateoffset?

Иван
  • 87
  • 1
  • 7

1 Answers1

0

You could do something like this:

s = pd.date_range('2019-01-01','2019-12-31', freq='D')

s[(s.dayofweek == 6) & (s.day>=15) & (s.day<=21)]

Output:

DatetimeIndex(['2019-01-20', '2019-02-17', '2019-03-17', '2019-04-21',
               '2019-05-19', '2019-06-16', '2019-07-21', '2019-08-18',
               '2019-09-15', '2019-10-20', '2019-11-17', '2019-12-15'],
              dtype='datetime64[ns]', freq=None)
Scott Boston
  • 147,308
  • 15
  • 139
  • 187