Python: get ordinal from time -


i want regression on several features, , 1 of them time. therefore, need convert time quantitative variable, e.g. integer.

in particular, obtain ordinal number datetime.time object. there direct method it?

i know can done method toordinal() datetime.date objects, same method not exist datetime.time

there doesn't seem built-in method in datetime module. format not meant ordinal values since doesn't include date , comparing events different dates give wrong order. if own code returning datetime.time recommend using timestamps time.time() in time module instead. timestamps can converted formatted time if need make human readable.

even though datetime.time doesn't have built in converter timestamp it's easy self, convert each time value seconds , add them up:

def dtt2timestamp(dtt):     ts = (dtt.hour * 60 + dtt.minute) * 60 + dtt.second     #if want microseconds     ts += dtt.microsecond * 10**(-6)     return ts 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -