gpt4 book ai didi

python - 如何使用 (np.busday_count) 与 pandas.core.series.Series

转载 作者:太空宇宙 更新时间:2023-11-04 04:22:26 25 4
gpt4 key购买 nike

我想计算两列类型 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)

关于python - 如何使用 (np.busday_count) 与 pandas.core.series.Series,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54234021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com