我正在尝试指定在国外的工作日,但是我无法使用pandas函数pd.bdate_range()
来识别假期。我的代码如下:
import pandas as pd
import datetime
weekmask = "Mon Tue Wed Thu Fri"
holidays = [datetime.datetime(2017, 1, 9), datetime.datetime(2017, 3, 20),
datetime.datetime(2017, 4, 13)]
BdaysCol2017 = pd.bdate_range(start = pd.datetime(2017, 1, 1),
end = pd.datetime(2017, 12, 31),
weekmask = weekmask,
holidays = holidays)
但是我在holidays
参数上收到以下错误:
ValueError: a custom frequency string is required when holidays or weekmask are passed, got frequency B
这是为什么?如何指定自定义假期?有一个更好的方法吗?
谢谢
答案 0 :(得分:0)
文档指定了有关周休和假期的信息:
仅在传递自定义频率字符串时使用
所以您需要:
BdaysCol2017 = pd.bdate_range(start = pd.datetime(2017, 1, 1),
end = pd.datetime(2017, 12, 31),
freq='C',
weekmask = weekmask,
holidays=holidays)