title: How to convert Python datetime dates to decimal/float years
body: <p>I am looking for a way to convert datetime objects to decimal(/float) year, including fractional part. Example:</p>
  <pre><code>&gt;&gt;&gt; obj = SomeObjet()
  &gt;&gt;&gt; obj.DATE_OBS
  datetime.datetime(2007, 4, 14, 11, 42, 50)
  </code></pre>
  <p>How do I convert <code>datetime.datetime(2007, 4, 14, 11, 42, 50)</code> to decimal years. By decimal format I mean the float value <code>2007.4523</code>, where the fractional part is the number of seconds from the beginning of the year (2007-01-01 till 2007-04-14), divided by the total number of seconds in that year (2007-01-01 till 2008-01-01).</p>
  <p>(NOTE: in statistical modeling (e.g. for linear regression), this is called <em><strong>&quot;time index&quot;</strong></em>)</p>