title: How can I get a curve of best fit using polyfit, when the x values are datetimes?
body: <p>An overview:
  I have a Django site, where I graph data. I need to generate a polynomial curve of best fit, but the x values for the graphs are either dates or datetimes. I am using polyfit on a numpy array. When I try to convert the datetimes into integers or floats, using <code>datetime_object.timestamp()</code> I get really weird coefficient values and the graph does not match the data at all. Is there any way that I can use the polyfit method with datetimes (or dates) to get more normal coefficient values that fit the data better?</p>
  
  <pre class="lang-py prettyprint-override"><code>milliseconds = []
  for i in pricingDateTimes:
      dt_obj = datetime.strptime(i, '%Y-%m-%d %H:%M:%S')
      milliseconds.append(dt_obj.timestamp() * 1000)  # I have also tried division by powers of 10 to get more reasonable coefficients
      x = array(milliseconds)
      y = array(pricingMetricData)
      quadratic = polyfit(x, y, 2)
  </code></pre>
  
  <p>So is there a way to get valid coefficients of data using polyfit and dates or datetimes as x values?
  Is there another way that I could get the coefficients for the curve of best fit with datetimes or dates?</p>
  
  <p>Thanks!</p>