python - unconverted data remains for only some of records -


i have dataset including timestamps of them have decimals in seconds, don't. need compare these timestamps , classify those. don't know how define format differently these records.

so, have decimals in seconds, can write:

a = datetime.strptime(time, "%h:%m:%s.%f") 

and don't have, write:

a = datetime.strptime(time, "%h:%m:%s") 

i need compare a timestamp.

use string.split function separate string 3 fields, , see if third 1 has ".". might want more error handling have provided here.

def has_seconds(a_string):     return "." in a_string.split(":")[2]  if has_seconds(a_time):     = datetime.strptime(a_time, "%h:%m:%s.%f") else:     = datetime.strptime(a_time, "%h:%m:%s")  

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -