T
T
Timebird2017-12-17 02:32:20
Python
Timebird, 2017-12-17 02:32:20

How to write a moving average implementation for a time series?

There is a set of dates in datetime format like: datetime.datetime(2017, 12, 8, 18, 0) .
There is some value for each date.
There are many dates/values.
I wrapped everything in a dataframe, tried to implement the simplest moving average method from Habr , or rather, this one:

def moving_average(series, n):
    return np.average(series[-n:])

Here series is actually an array of times, and the forecast is made n hours/days ahead.
So.
The calculation fails because the interpreter cannot add:
datetime.datetime(2017, 12, 8, 18, 0) + datetime.datetime(2017, 12, 8, 19, 0) .
And how do they work with such a format in time series?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question