How to convert a datetime.time type to float in python?
<p>I am performing a data analysis with python. I need to convert a data type from datatime.time to float, something like what makes Excel when we change the cell format from "time" to "number".</p>

<p><a href="http://i.stack.imgur.com/fwvHt.png" rel="nofollow"><img src="http://i.stack.imgur.com/fwvHt.png" alt="enter image description here"></a></p>

<p>I could load the data on excel, change the columns format, export them again to CSV and finally load again into a dataframe, but I don't want to perform all that process again.</p>

<p>Thanks for your help!</p>

<p>The decimal number used by Excel is simply the fraction of a day that a time represents, with midnight being 0.0.  You simply take the hours, minutes, and seconds in the time and divide by the fraction of a day they represent:</p>

<pre><code>def excel_time(time):
    return time.hour / 24.0 + time.minute / (24.0*60.0) + time.second / (24.0*60.0*60.0) + time.microsecond / (24.0*60.0*60.0*1000000.0)
</code></pre>

python python-3.x time