如何在pandas.core.series.Series中使用(np.busday_count) [英] how to use (np.busday_count) with pandas.core.series.Series

查看:64
本文介绍了如何在pandas.core.series.Series中使用(np.busday_count)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to calculate the business days between two columns type pandas.core.series.Series

接收日期完成日期之间#仅在工作日内
我正在尝试使用np.busday_count(接收日期,完成日期,weekmask =星期五星期六")但是我得到了:

between Received date and complete date #business days only
I was trying to use np.busday_count(Received date,complete date,weekmask= "Fri Sat") but I was getting :

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

TypeError: Iterator operand 0 dtype could not be cast from dtype('M8[us]') to dtype('M8[D]') according to the rule 'safe'

这是我数据框的一部分:

Here is part of my dataframe:

     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

推荐答案

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

As indicated in the error, convert to 'datetime64[D]' before using 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)

这篇关于如何在pandas.core.series.Series中使用(np.busday_count)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆