Gingerbread
Gingerbread

Reputation: 2122

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

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!

Upvotes: 1

Views: 8682

Answers (1)

ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19375

easy little gingerbread, use this column instead

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

Upvotes: 4

Related Questions