时间戳:无法将 NumPy 数组转换为张量

Timestamp : Failed to convert a NumPy array to a Tensor

我有 pandas 数据框,如下所示:

time                                value
2019-05-24 04:15:35.742000+00:00    -0.085714

当我尝试这样做时,在我的代码中有一处:

hist = model.fit(
    X_train, y_train, 
...
)

其中 X_train 来自数据框,看起来像:

array([[[Timestamp('2019-05-21 14:16:37.091000'), -0.22857142857142856,          1.3553382233088835],

我收到以下错误:

Failed to convert a NumPy array to a Tensor (Unsupported object type Timestamp)

编辑:

tr['execution_time'] = pd.to_datetime(tr.execution_time).dt.tz_localize(None) 

这也没有帮助。

首先我们必须将它转换为datetime对象。

df['execution_time'] = pd.to_datetime(df.execution_time).dt.tz_localize(None)

之后我们必须使用 timestamp() 函数

datetime 对象转换为浮点值
for i in range(len(df)):
  df['execution_time'][i]=df['execution_time'][i].timestamp()

之后我们可以将值转换为 float

df = df.astype('float32')

然后可以轻松转换为张量。