I am new to python and programming in general, so goodbye to any simple errors / things that should be obvious.
What I'm trying to do is pretty simple, I just want to set a linear trend (1st polynomial) to a bunch of time series to see if slopes are positive or negative. Now I'm just trying to get it to work once.
Problem: it seems that both pandas and numpy cannot do regressions for datetimes. My time is not regular (usually 1 day per month, but not on the same day), so you cannot use the sentence proposed in Linear regression from the Pandas time series
My csv time series looks like this:
StationName, year, month, day, depth, NO3-N, PO4-P, TotP, TotN, Kvarnbacken (Savaran), 2003, 2, 25, 0.5, 46, 9, 14, 451 Kvarnbacken (Savaran), 2003, 3, 18, 0.5, 64, 15, 17, 310 Kvarnbacken (Savaran), 2003, 3, 31, 0.5, 76, 7, 19, 566
I still have
import datetime as dt from scipy import stats import numpy as np
I tried
slope, intercept, r_value, p_value, std_err = stats.linregress(data.date, data.TotP)
and got a TypeError error: ufunc add cannot use operands with dtype types ('
I also tried
coefP = np.polyfit(data.date, data.TotP, 1) polyP = np.poly1d(coefP) ys = polyP(data.date) print 'For P: coef, poly' print coefP print polyP
and got the same error.
I guess the easiest way is to do something when I just count the days from the first measurement, and then just do a regression from days_since to the total phosphorus concentration (totP), but I'm not sure the easiest way to do this, or if there is another trick.