pandas AttributeError: 'DataFrame' 对象没有属性 'datetime'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42894058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: 'DataFrame' object has no attribute 'datetime'
提问by Gingerbread
I am getting the following error for the code below:
我收到以下代码的以下错误:
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')
My dataframe has two columns and it looks like this:
我的数据框有两列,它看起来像这样:
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
To run the anomaly detection code, it says the following:
要运行异常检测代码,它说明如下:
The input timestamp column must be a float or integer of the unix timestamp, not date
time columns, date strings or pd.TimeStamp columns.
So, I tried following the same using the code above. However, I keep getting this error.
因此,我尝试使用上面的代码执行相同的操作。但是,我不断收到此错误。
AttributeError: 'DataFrame' object has no attribute 'datetime'
I updated pandas as that was a solution in one of the other SO posts similar to this. But I still keep getting this error. Any help will be much appreciated! thanks!
我更新了Pandas,因为这是其他与此类似的 SO 帖子之一中的解决方案。但我仍然不断收到此错误。任何帮助都感激不尽!谢谢!
回答by ??????
easy little gingerbread, use this column instead
简单的小姜饼,改用这个列
df['other_date'] = df['date'].astype(np.int64) // 10**9
df['other_date'] = df['date'].astype(np.int64) // 10**9