Linear regression with pandas time series
<p>I have a dataframe object which contains 1 seconds intervals of the EUR_USD currency pair. But in theory it could be any interval and in this case it could look like this:</p>

<pre><code>2015-11-10 01:00:00+01:00    1.07616
2015-11-10 01:01:00+01:00    1.07605
2015-11-10 01:02:00+01:00    1.07590
2015-11-10 01:03:00+01:00    1.07592
2015-11-10 01:04:00+01:00    1.07583
</code></pre>

<p>I'd like to use linear regression to draw a trend line from the data in dataframe, but I'm not sure what the best way are to do that with time series, and even such a small interval of time series.</p>

<p>So far I've messed around by replacing the time by (and this is just to show where I'd like to go with it) a list ranging from 0 to the time series list length.</p>

<pre><code>x = list(range(0, len(df.index.tolist()), 1))
y = df["closeAsk"].tolist()
</code></pre>

<p>Using numpy to do the math magic</p>

<pre><code>fit = np.polyfit(x,y,1)
fit_fn = np.poly1d(fit)
</code></pre>

<p>Lastly I draw the function along with the df["closeAsk"] to make sense of the trend.</p>

<pre><code>plt.plot(x,df["closeAsk"], '-')
plt.plot(x,y, 'yo', x, fit_fn(x), '--k')
plt.show()
</code></pre>

<p>However now the x-axis is just meaningless numbers, instead I'd like for them to show the time series.</p>