如何将 (np.busday_count) 与 pandas.core.series.Series 一起使用

Kha*_*far 5 python datetime numpy python-3.x pandas

我想计算两列类型之间的工作日 pandas.core.series.Series

接收日期完成日期# 个工作日
之间 ,我试图使用 np.busday_count(Received date,complete date,weekmask= "Fri Sat") 但我得到:

TypeError: 迭代器操作数 0 dtype 无法根据规则 'safe' 从 dtype('M8[us]') 转换为 dtype('M8[D]')

这是我的数据框的一部分:

     Received   Complete
0  2018-09-10 2018-09-25
1  2018-07-16 2018-08-13
2  2018-07-05 2018-07-11
3  2018-07-05 2018-07-23
4  2018-07-26 2018-08-14
5  2018-07-04 2018-08-28
6  2018-07-05 2018-07-10
7  2018-07-05 2018-07-10
8  2018-07-05 2018-07-22
9  2018-07-05 2018-07-22
10 2018-07-05 2018-07-19
Run Code Online (Sandbox Code Playgroud)

jpp*_*jpp 7

如错误所示,在使用'datetime64[D]' 之前np.busday_count转换为:

res = np.busday_count(df['Received'].values.astype('datetime64[D]'),
                      df['Complete'].values.astype('datetime64[D]'),
                      weekmask= "Fri Sat")

# array([ 4,  8,  2,  6,  6, 16,  2,  2,  6,  6,  4], dtype=int64)
Run Code Online (Sandbox Code Playgroud)