I did find this solution 点击这里查看文章 但仍不完全是我所要的。该方案计算了2个日期之间的所有天数,包括周末。那么,是否有一个解决方案可以在计算中排除周末?
如何用Python计算到日期之间的工作日?
1
人不认可
1
个评论
也许日历模块可以提供帮助?
docs.python.org/3/library/calendar.html#module-calendar
Jorge Bustos Torres
发布于
2022-08-11
1
个回答
Jorge Bustos Torres
发布于
2022-08-11
已采纳
0
人赞同
因此,我所做的是采取这种解决方案,并以这种方式扩展它。
crtD = datetime.datetime.strptime(pd.loc[x,'createDate'], '%m/%d/%Y') # start date
tdyD = datetime.datetime.today() # end date
dayx = tdyD - crtD # number of days between start and end date. Includes weekends
wkds = dayx.days + 1 # eliminates time stamp and just leaves the number of days and adds 1 day