我试图设计一个np.where
参数,它有以下输入
r_label = np.array([['Fiscal data as of Dec 31 2016', '2016', '2015', '2014'],
['Fiscal data as of Dec 31 2016', '2016', '2015', '2014']],
dtype='<U29')
x = pd.Int64Index([12, 12], dtype='int64')
r_values_count = 2
check = np.isnat(pd.to_datetime(r_label[:,1:][0], errors='coerce', format='%b %d %Y')).all()
if_true = [pd.to_datetime(r_label[:,1:][_], errors='coerce').map(lambda t: t.replace(month=x[_])) for _ in range(r_values_count)]
if_false = [pd.to_datetime(r_label[:,1:][_], errors='coerce', format='%b %d %Y') for _ in range(r_values_count)]
np.where(check, if_true, if_false)
但是我得到了错误ValueError: cannot convert float NaN to integer
。np.where
参数的所有三个参数都能很好地独立工作,我不明白为什么它现在在{
目前没有回答
相关问题 更多 >
编程相关推荐