在Python中获取日期在两个日期之间的工作日数

问题描述:

正如我在网站上搜索以获取python中的工作日数一样,但是我也需要工作日的日期.

As I have searched in website to get the number of weekdays in python, but I need the date of the weekdays too.

我的输入将是:

 start date = 01-03-2019
 end_date = 15-03-2019
 days = monday , tuesday

预期的输出:

我需要打印星期一和星期二的数量以及日期.

which I need is to print the number of mondays and tuesdays along with the date.

使用 pandas.to_datetime pandas.date_range :

import pandas as pd

start_date = '01-03-2019'
end_date = '15-03-2019'
days = ['Monday', 'Tuesday']

dates = pd.to_datetime([start_date, end_date], format='%d-%m-%Y')
pd.date_range(dates[0],dates[1],freq='1d').day_name().value_counts()[days]
Monday     2
Tuesday    2
dtype: int64