0

I want get the count of busy days between this two pandas series("datetime64[ns]")

    DT_DEADLINE DT_DELIVERY
0   2021-08-05  2021-08-05
1   2021-08-09  2021-08-16
2   2021-08-10  2021-08-15
3   2021-08-09  2021-08-15
4   2021-08-05  2021-08-10

I try do like that but get the erro bellow:

of['bdays'] = np.busday_count(of["DT_DEADLINE"].dt.date, of["DT_DELIVERY"].dt.date)

ERROR MESSAGE:

TypeError: Cannot cast array data from dtype('O') to dtype('<M8[D]') according to the rule 'safe'
  • Does this answer your question? [how to use (np.busday\_count) with pandas.core.series.Series](https://stackoverflow.com/questions/54234021/how-to-use-np-busday-count-with-pandas-core-series-series) – mozway Aug 29 '21 at 13:43

1 Answers1

0

Maybe...

df['busday_count'] = np.busday_count(df['DT_DEADLINE'].values.astype('datetime64[D]'),
                      df['DT_DELIVERY'].values.astype('datetime64[D]'))

print(df)

  DT_DEADLINE DT_DELIVERY  busday_count
0  2021-08-05  2021-08-05             0
1  2021-08-09  2021-08-16             5
2  2021-08-10  2021-08-15             4
3  2021-08-09  2021-08-15             5
4  2021-08-05  2021-08-10             3
MDR
  • 2,610
  • 1
  • 8
  • 18