![](/img/trans.png)
[英]UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('float64')
[英]how can I solve this Error "ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('float64')"?
我必須規范化我的數據框以進行規范化的預測算法我收到此錯誤
如果我想解釋更多,我的數據框就像這種格式,尺寸為 1991 行 × 1691 列
代碼 | 通話時間 | 211323 | 224250 |
---|---|---|---|
6968 | 2022-04-26 02:44:24.373376 | 61800000.0 | 133200000.0 |
我的代碼是:
column_indices = {name: i for i, name in enumerate(Code.columns)}
n = len(df1)
train_df = df1[0:int(n*0.7)]
val_df = df1[int(n*0.7):int(n*0.9)]
test_df = df1[int(n*0.9):]
num_features = df1.shape[1]
train_mean = train_df.mean()
train_std = train_df.std()
train_df = (train_df - train_mean) / train_std
val_df = (val_df - train_mean) / train_std
test_df = (test_df - train_mean) / train_std
然后我得到這個錯誤:
ufunc 'subtract' 不能使用類型為 dtype('<M8[ns]') 和 dtype('float64') 的操作數
請幫幫我。
您很可能對CallTime
列中的值有疑問。 以這個導致相同錯誤的示例為例:
time_s = pd.Series([pd.Timestamp.now() + pd.Timedelta(seconds=x) for x in range(10)])
# this will raise: numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('float64')
error_operation = time_s - 2.0
建議:確保df1['CallTime'].dtype
是日期時間格式:
time_s.dtype
dtype('<M8[ns]')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.