Skip to content Skip to sidebar Skip to footer

Typeerror: Unsupported Operand Type(s) For +: 'timestamp' And 'float'

i have, x = [2017-06-07, 2017-07-19] y = [155.98, 151.42] i want to draw a straight line and find the y intercept(3rd point). for now am using the polynomial fit method to a draw

Solution 1:

np.polyfit is clearly expecting pure numeric values. You can convert yours like this:

coefficients = np.polyfit(np.asarray(x).astype(float), y, 1)

That will convert your timestamps to some sort of epoch time, and then you can do the fit and convert back to timestamps if you need to (more likely you will convert other X values to floats using the same logic so you can make predictions using the model).

Solution 2:

If the function doesn't support datetimes then it may be simplest to convert them to floats (eg. seconds since t0).

Post a Comment for "Typeerror: Unsupported Operand Type(s) For +: 'timestamp' And 'float'"