0

我正在尝试运行此代码并获取此错误 .m 数据如下所示 在此处输入图像描述

TypeError: 不能从 [datetime64[ns, UTC]] 到 [int32] 键入 datetimelike

    import numpy as np
    import pandas as pd
    import seaborn as sns
    from sklearn.ensemble import IsolationForest
    data = pd.read_csv("data.csv", parse_dates=['timestamp'])
    data['timestamp'] = data['timestamp'].astype('int')
    model=IsolationForest(n_estimators=50, max_samples='auto', contamination=float(0.1),max_features=1.0)
    model.fit(data[['timestamp','a','b','c','d','e','f','g',    'h','i','j','k']])
    data['scores']=model.decision_function(data[['timestamp','a','b','c','d','e','f','g',   'h','i','j','k']])
    data['anomaly']=model.predict(data[['timestamp','a','b','c','d','e','f','g',    'h','i','j','k']])

桌子是空的

4

1 回答 1

1

试试这个:

data['timestamp'] = data['timestamp'].astype('datetime64[s]').astype('int')

它首先转换为秒,然后转换为 int。

于 2022-02-05T00:55:05.800 回答