1

I am trying to get all business day of a year by using pandas date_range function.But i am missing some necessary parameters to get my desired result.

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

DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04',
               '2015-01-05', '2015-01-06', '2015-01-07', '2015-01-08',
               '2015-01-09', '2015-01-10',
               ...
               '2015-12-22', '2015-12-23', '2015-12-24', '2015-12-25',
               '2015-12-26', '2015-12-27', '2015-12-28', '2015-12-29',
               '2015-12-30', '2015-12-31'],
              dtype='datetime64[ns]', length=365, freq='D')

I am getting all days of that year which is not i want.

piRSquared
  • 285,575
  • 57
  • 475
  • 624
Rishindra
  • 39
  • 4

1 Answers1

2

Use the freq B for business days

pd.date_range('2015-01-01', '2015-12-31', freq='B')

DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-05', '2015-01-06',
               '2015-01-07', '2015-01-08', '2015-01-09', '2015-01-12',
               '2015-01-13', '2015-01-14',
               ...
               '2015-12-18', '2015-12-21', '2015-12-22', '2015-12-23',
               '2015-12-24', '2015-12-25', '2015-12-28', '2015-12-29',
               '2015-12-30', '2015-12-31'],
              dtype='datetime64[ns]', length=261, freq='B')
piRSquared
  • 285,575
  • 57
  • 475
  • 624