I have the following dataframe with a couple of columns with the beginning and the end of the dates' range I'd like to check the business days between:
In [139]: df.head()
Out[139]:
Num Material Kilos Sold Date Year Week_Number \
0 5881999 1020252 629 1434120 2019-06-14 2019 24
1 94623000 1022746 598 1572740 2019-06-12 2019 24
2 77274650 1022470 920 1684520 2019-06-25 2019 26
3 94623000 1022643 1215 2563650 2019-01-23 2019 4
40 94623000 1021478 581 1528030 2018-10-23 2018 43
Week_init Week_end
0 2019-06-10 2019-06-15
1 2019-06-10 2019-06-15
2 2019-06-24 2019-06-29
3 2019-01-21 2019-01-26
40 2018-10-22 2018-10-27
However, when I try to use the np.busday_count
funcion as follows:
df["b_days"] = np.busday_count(df['Week_init'], df['Week_fin'],
weekmask=bday_custom.weekmask, holidays=bday_custom.holidays)
I get the following error:
TypeError: Iterator operand 0 dtype could not be cast from dtype('M8[ns]') to dtype('M8[D]') according to the rule 'safe'
Looks like the function is complaining about the Week_init
and Week_end
dtypes, but I've tried changing it's type without success as follows:
df['Week_init'] = df['Week_init'].values.astype('datetime64[D]')
However, dtype keeps as:
In [140]: df['Week_init'].dtype
Out[140]: dtype('<M8[ns]')
Any help please?