我目前正在使用
np.busday_count(day1, day2))
计算两个日期之间的工作日数量。如何排除在工作日中的节假日?
import pandas as pd
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
day1 = '2010-01-01'
day2 = '2010-01-15'
us_bd = CustomBusinessDay(calendar=USFederalHolidayCalendar())
print(pd.DatetimeIndex(start=day1,end=day2, freq=us_bd))
输出:
DatetimeIndex(['2010-01-04', '2010-01-05', '2010-01-06', '2010-01-07',
'2010-01-08', '2010-01-11', '2010-01-12', '2010-01-13',
'2010-01-14', '2010-01-15'],
dtype='datetime64[ns]', freq='C')
print(len(pd.DatetimeIndex(start=day1,end=day2, freq=us_bd)))
输出:
10
pd.DatetimeIndex()
的start
和end
参数已被删除。请改用pd.date_range(start=day1, end=day2, freq=us_bd)
。 - Julian