【问题标题】:AttributeError: 'DataFrame' object has no attribute 'datetime'AttributeError:“DataFrame”对象没有属性“datetime”
【发布时间】:2017-08-11 04:01:44
【问题描述】:

我收到以下代码的以下错误:

import time
import datetime
from pyculiarity import detect_ts
import pandas as pd



data = pd.read_csv('data.csv', usecols=['date', 'money_spent'])
data = data[['date', 'money_spent']]
data['date'] = pd.to_datetime(data['date'])
data['date'] = (data['date'] - dt.datetime(1970,1,1)).dt.total_seconds()
results = detect_ts(data, max_anoms=0.05, alpha=0.001, direction='both')

我的数据框有两列,如下所示:

date                       money_spent
2015-08-05 00:59:19           11.94
2015-10-29 18:23:04            5.76
2015-10-25 17:50:48           25.84
2015-09-05 17:39:43           68.89

要运行异常检测代码,它会显示以下内容:

The input timestamp column must be a float or integer of the unix timestamp, not date
                                time columns, date strings or pd.TimeStamp columns.

所以,我尝试使用上面的代码进行相同的操作。 但是,我不断收到此错误。

AttributeError: 'DataFrame' object has no attribute 'datetime'

我更新了 pandas,因为这是与此类似的其他 SO 帖子中的一个解决方案。但我仍然不断收到这个错误。 任何帮助都感激不尽!谢谢!

【问题讨论】:

  • dt 中的dt.datetime(1970,1,1)) 是什么?
  • dt 到底在哪里定义的?

标签: python pandas


【解决方案1】:

简单的小姜饼,改用这个专栏

df['other_date'] = df['date'].astype(np.int64) // 10**9

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-10-23
  • 2017-01-24
  • 2018-10-10
  • 2019-08-18
  • 2021-01-20
  • 2020-05-16
  • 2018-10-04
  • 2021-04-05
相关资源
最近更新 更多