我想计算两列类型 pandas.core.series.Series 之间的工作日
在接收日期和完成日期之间#仅限工作日
我试图使用 np.busday_count(Received date,complete date,weekmask= "Fri Sat")但我得到了:
TypeError: Iterator operand 0 dtype could not be cast from dtype('M8[us]') to dtype('M8[D]') according to the rule 'safe'
这是我的数据框的一部分:
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
如错误中所示,使用 np.busday_count
转换为 'datetime64[D]'
:
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)
我是一名优秀的程序员,十分优秀!