有没有办法让周日到周四的营业日期范围被视为营业日和
示例输出:
>>> 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 :(得分: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')
答案 1 :(得分:0)
您可以过滤掉不想要的日子:
dates=pd.date_range('2016-5-10','2016-5-17').to_frame(name='d') # convert to frame so we can run query on it
dates.query('d.dt.strftime("%a") not in ["Fri","Sat"]').index
DatetimeIndex(['2016-05-10', '2016-05-11', '2016-05-12', '2016-05-15',
'2016-05-16', '2016-05-17'],
dtype='datetime64[ns]', freq=None)
d.dt.strftime("%a")
它将仅将时间戳记作为日期名称,例如Sun Mon.。