parsing - How do I parse dates with more than 24 hours in dateutil's parser in Python 3? -
i have bunch of times in column written "27:32:18", meaning waiting 27 hours, 32 minutes, , 18 seconds. maintain getting "valueerror: hr must in 0..23" whenever seek parse these values.
how should go parsing values or converting them more standard format? tried next test on single value:
time1 = "56:42:12" time2 = time1.split(':') time2 = [int(n) n in time2] time2.insert(0, time2[0] // 24) time2[1] %= 24
at point, time2 list consisting of [2, 8, 42, 12], equivalent 2 days, 8 hours, 42 minutes, , 12 seconds. how go converting python datetime representation in days, hours, minutes, , seconds in way allow python parse it? note doing unsupervised clustering on these time values, represent waiting times.
you don't have date, have time duration. may related dates , timestamps, in same units of time involved , displayed timestamps.
as such, cannot utilize dateutil
parsing such values. easy plenty split out , parse yourself:
hours, minutes, seconds = map(int, time1.split(':'))
you can utilize datetime.timedelta()
object represent duration:
td = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
this'll track delta in terms of days, seconds , microseconds:
>>> import datetime >>> time1 = "56:42:12" >>> hours, minutes, seconds = map(int, time1.split(':')) >>> datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds) datetime.timedelta(2, 31332)
python parsing datetime python-3.x
No comments:
Post a Comment