【发布时间】:2019-11-24 10:41:03
【问题描述】:
我想计算两个日期之间的工作日(不包括星期日和星期六),一个在数据框列内,另一个是今天的当前日期,但出现错误:
REF8_df['Days_Dif'] = np.busday_count(REF8_df['Session1_Date'], Todays_Date)
File "<__array_function__ internals>", line 6, in busday_count
TypeError: Iterator operand 0 dtype could not be cast from dtype('<M8[ns]') to dtype('<M8[D]') according to the rule 'safe'
我的代码:
df = Main_Database['Session1_Date']
Todays_Date = np.datetime64('today', dtype='datetime64[D]')
df['Session1_Date'] = df['Session1_Date'].values.astype('datetime64[D]')
df['Days_Difference'] = np.busday_count(df['Session1_Date'], Todays_Date)
我很困惑为什么这不起作用?
【问题讨论】:
标签: python numpy dataframe datetime