Skip to content

Instantly share code, notes, and snippets.

View MichaelStetner's full-sized avatar

Michael Stetner MichaelStetner

  • Massachusetts Institute of Technology
  • Cambridge, MA, USA
View GitHub Profile
@MichaelStetner
MichaelStetner / total_seconds.py
Created October 31, 2017 20:29
Convert any timedelta to seconds
def total_seconds(timedelta):
"""Convert timedeltas to seconds
In Python, time differences can take many formats. This function can take
timedeltas in any format and return the corresponding number of seconds, as
a float.
Beware! Representing timedeltas as floats is not as precise as representing
them as a timedelta object in datetime, numpy, or pandas.