2016-05-14 130 views
0

的第一天,有沒有辦法讓在那裏週日至週四被視爲工作日和大熊貓:bdate_range第一套週日

示例輸出業務的日期範圍:

>>> import pandas as pd 
>>> pd.bdate_range('2016-5-10','2016-5-17') 
DatetimeIndex(['2016-05-10', '2016-05-11', '2016-05-12', '2016-05-13', 
      '2016-05-16', '2016-05-17'], 
      dtype='datetime64[ns]', freq='B') 

所需的輸出:

DatetimeIndex(['2016-05-10', '2016-05-11', '2016-05-12', '2016-05-15', 
      '2016-05-16', '2016-05-17'], 
      dtype='datetime64[ns]', freq='B') 

回答

0

您可以使用custom business days

weekmask = 'Sun Mon Tue Wed Thu' 
custombday = pd.offsets.CustomBusinessDay(weekmask=weekmask) 

print pd.bdate_range('2016-5-10','2016-5-17', freq=custombday) 

DatetimeIndex(['2016-05-10', '2016-05-11', '2016-05-12', '2016-05-15', 
       '2016-05-16', '2016-05-17'], 
       dtype='datetime64[ns]', freq='C')