1.引入相关的包
from datetime import date, datetime, timedelta
import calendar
import pandas as pd
from workalendar.asia import China
from dateutil import rrule
2.节假日计算
1.由于节假日包中没有2018年之前的相关数据,所以进行了手动添加并转化为dataframe:
hol = {"2016-12-31":"New year","2017-01-01":"New year", "2017-01-02":"New year", "2017-01-27":"Chinese New Year's eve",
"2017-01-28":"Chinese New Year", "2017-01-29":"Spring Festival", "2017-01-30":"Spring Festival", "2017-01-31":"Spring Festival",
"2017-02-01":"Spring Festival","2017-02-02":"Spring Festival", "2017-04-02":"Ching Ming Festival",
"2017-04-03":"Ching Ming Festival", "2017-04-04":"Ching Ming Festival", "2017-04-29":"Labour Day Holiday",