我正在对日期和值数据进行聚类。当执行k均值聚类时,数据未拟合到模型中,显示此错误
k_means = KMeans(n_clusters=2)
k_means.fit(df)
错误:
ValueError Traceback (most recent call last)
<ipython-input-43-caf6280a5928> in <cell line: 2>()
1 k_means = KMeans(n_clusters=2)
--> 2 k_means.fit(df)
-> 2070 return np.asarray(self._values, dtype=dtype)
ValueError: could not convert string to float: '2020-12-22 00:00:00'
so i use to convert date into timestamp so that fitted into model
but while conversion into timestamp from date showing following error
df["stamp"] = df["Alert_Time"].values.astype(np.int64) // 10 ** 9
ValueError Traceback (most recent call last)
<ipython-input-50-8c3cf615eeda> in <cell line: 1>()
-> 1 df["stamp"]=df["Alert_Time"].values.astype(np.int64) // 10 ** 9
ValueError: invalid literal for int() with base 10: '2020-12-22'
1条答案
按热度按时间axr492tv1#
可以使用
pd.to_datetime
:Minimal Reproducible Example: