Skip to content

Instantly share code, notes, and snippets.

@rashmibanthia
Created April 14, 2016 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashmibanthia/e35287e0462ac99a7d557308a63180d1 to your computer and use it in GitHub Desktop.
Save rashmibanthia/e35287e0462ac99a7d557308a63180d1 to your computer and use it in GitHub Desktop.
import pandas as pd
#Convert timedelta to number of seconds
td = pd.to_timedelta ("22 days 04:37:08")
print(td," is ",(td / np.timedelta64(1, 's')).astype(int)," seconds")
#Convert seconds to hh:mm:ss
sec = 63914
print(sec, " seconds is " ,pd.to_timedelta(sec, unit='s'))
#difference between two dates in seconds
a = pd.Timestamp('2015-09-22 01:20:44.551')
b = pd.Timestamp('2015-09-22 02:55:15.649')
print((b-a).seconds)
#difference
a = pd.Timestamp('02:30:10.917 18-09-2015')
b = pd.Timestamp('02:35:57.573 18-09-2015')
print((b-a).seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment