python 如何从开始日期 + 不包括周末的天数获取日期

python how to get date from a start date + no of days excluding weekends

我需要 python 函数来获取结束日期,输入的开始日期和不包括周末的天数。

对于前开始日期 = 01-01-2021 并且天数是 40 如何结束结束日期不包括周末,即日历日。

请帮忙。

使用bdate_range:

d = pd.bdate_range('01-01-2021', periods=40)
print (d)
DatetimeIndex(['2021-01-01', '2021-01-04', '2021-01-05', '2021-01-06',
               '2021-01-07', '2021-01-08', '2021-01-11', '2021-01-12',
               '2021-01-13', '2021-01-14', '2021-01-15', '2021-01-18',
               '2021-01-19', '2021-01-20', '2021-01-21', '2021-01-22',
               '2021-01-25', '2021-01-26', '2021-01-27', '2021-01-28',
               '2021-01-29', '2021-02-01', '2021-02-02', '2021-02-03',
               '2021-02-04', '2021-02-05', '2021-02-08', '2021-02-09',
               '2021-02-10', '2021-02-11', '2021-02-12', '2021-02-15',
               '2021-02-16', '2021-02-17', '2021-02-18', '2021-02-19',
               '2021-02-22', '2021-02-23', '2021-02-24', '2021-02-25'],
              dtype='datetime64[ns]', freq='B')